<commit_before>/* 
 * Test Module: Basic
 * Ensures that CacheIt can do its basic tasks.
 *
 */
module("basic", {
  setup: function() {
    Backbone.sync = function(method, model, options) {
      // Create a new count or reuse and increment.
      var count = model._count = model._count ? ++model._count : 1;
      var def = $.Deferred();

      // Simulate asynchronous traffic.
      window.setTimeout(function() {
        // Call success with the increment.
        if (model instanceof Backbone.Model) {
          def.resolve({ count: count });
          return options.success({ count: count });
        }

        // This is a Collection.
        options.success([{ count: count }]);
        def.resolve([{ count: count }]);
      }, (Math.random()*100)+100);

      return def;
    };

    this.Collection = Backbone.Collection.extend({
      url: "notused"
    });
  }
});

asyncTest("Basic behaviors work correctly.", function() {
  var c = new this.Collection();

  c.fetch().then(function(c) {
    equal(c.length, 1, "Length is correct");
    ok(c.at(0) instanceof Backbone.Model, "First element is a Backbone.Model.");
    equal(c.at(0).get("count"), 1, "Only called once.");

    c.fetch().then(function() {
      equal(c.length, 1, "Length is correct.");
      equal(c.at(0).get("count"), 1, "Only called once.");

      start();
    });
  });
});

asyncTest("Reloading works correctly.", function() {
  var c = new this.Collection();

  c.fetch().then(function(c) {
    equal(c.length, 1, "Length is correct.");
    ok(c.at(0) instanceof Backbone.Model, "First element is a Backbone.Model.");
    equal(c.at(0).get("count"), 1, "Only called once.");

    c.fetch({ reload: true }).then(function() {
      equal(c.length, 1, "Length is correct.");
      equal(c.at(0).get("count"), 2, "Called twice.");

      start();
    });
  });
});
<commit_msg>updated unit test to ensure ordering is correct<commit_after>/* 
 * Test Module: Basic
 * Ensures that CacheIt can do its basic tasks.
 *
 */
module("basic", {
  setup: function() {
    Backbone.sync = function(method, model, options) {
      // Create a new count or reuse and increment.
      var count = model._count = model._count ? ++model._count : 1;
      var def = $.Deferred();

      // Simulate asynchronous traffic.
      window.setTimeout(function() {
        // Call success with the increment.
        if (model instanceof Backbone.Model) {
          def.resolve({ count: count });
          return options.success({ count: count });
        }

        // This is a Collection.
        options.success([{ count: count }]);
        def.resolve([{ count: count }]);
      }, (Math.random()*100)+100);

      return def;
    };

    this.Collection = Backbone.Collection.extend({
      url: "notused"
    });
  }
});

asyncTest("Basic behaviors work correctly.", 5, function() {
  var c = new this.Collection();

  c.fetch().then(function(c) {
    equal(c.length, 1, "Length is correct");
    ok(c.at(0) instanceof Backbone.Model, "First element is a Backbone.Model.");
    equal(c.at(0).get("count"), 1, "Only called once.");

    c.fetch().then(function() {
      equal(c.length, 1, "Length is correct.");
      equal(c.at(0).get("count"), 1, "Only called once.");

      start();
    });
  });
});

asyncTest("Reloading works correctly.", 5, function() {
  var c = new this.Collection();

  c.fetch().then(function(c) {
    equal(c.length, 1, "Length is correct.");
    ok(c.at(0) instanceof Backbone.Model, "First element is a Backbone.Model.");
    equal(c.at(0).get("count"), 1, "Only called once.");

    c.fetch({ reload: true }).then(function() {
      c.fetch({ reload: true }).then(function() {
        equal(c.length, 1, "Length is correct.");
        equal(c.at(0).get("count"), 3, "Called three times.");

        start();
      });
    });
  });
});

asyncTest("Order maintained", function() {
  var c = new this.Collection();

  c.fetch().then(function() {
    c.fetch({ reload: true }).then(function() {
      equal(c.at(0).get("count"), 2, "Rendered twice inside the deferred.");
      start();
    });
  });
});

{'fraction_non_alphanumeric': 0.18184031158714703, 'fraction_numerical': 0.011197663096397274, 'mean_word_length': 2.681899641577061, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2678149', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1247, 'n_words': 342}