Sha256: dd2ea02953376fcf8d38a7132ff2e04083bf6085ed97890881de57b2944595a2

Contents?: true

Size: 1.86 KB

Versions: 37

Compression:

Stored size: 1.86 KB

Contents

(function(root) {
  var store;
  var query;
  var recordArray;

  module("SC.RecordArray - implements array content observers", {
    setup: function() {
    },

    teardown: function() {
      root.MyRecord = undefined;
    }
  });

  test("notifies when a record is added to the store that matches a query", function() {
    var callCount = 0,
        lastRemovedCount = 0,
        lastAddedCount = 0;

    SC.run(function() {
      store = SC.Store.create();
      root.MyRecord = SC.Record.extend();
      query = SC.Query.local(MyRecord);

      recordArray = store.find(query);

      recordArray.addArrayObservers({
        didChange: function(start, removedCount, addedCount) {
          lastRemovedCount = removedCount;
          lastAddedCount = addedCount;
        },

        willChange: function() {}
      });

      store.createRecord(MyRecord, {});
    });

    equals(lastAddedCount, 1);
    equals(lastRemovedCount, 0);
    equals(recordArray.get('length'), 1);
  });

  test("notifies when a record is removed from the store that matches a query", function() {
    var lastRemovedCount = 0,
        lastAddedCount = 0;

    var record;

    SC.run(function() {
      store = SC.Store.create();
      root.MyRecord = SC.Record.extend();
      query = SC.Query.local(MyRecord);

      recordArray = store.find(query);

      recordArray.addArrayObservers({
        didChange: function(start, removedCount, addedCount) {
          lastRemovedCount = removedCount;
          lastAddedCount = addedCount;
        },

        willChange: function() {}
      });

      record = store.createRecord(MyRecord, {
        guid: 1
      });
    });

    equals(lastAddedCount, 1);
    equals(lastRemovedCount, 0);

    SC.run(function() {
      record.destroy();
    });

    equals(lastAddedCount, 0);
    equals(lastRemovedCount, 1);
    equals(recordArray.get('length'), 0);
  });
})(this);

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
sproutcore-1.11.0 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.11.0.rc3 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.11.0.rc2 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.11.0.rc1 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.10.3.1 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.10.2 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.10.1 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.10.0 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.10.0.rc.3 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.10.0.rc.2 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.10.0.rc.1 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.9.2 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.9.1 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.9.0 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.8.2.1 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.8.1 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.8.0 lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.7.1.beta-java lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.7.1.beta lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js
sproutcore-1.6.0.1-java lib/frameworks/sproutcore/frameworks/datastore/tests/system/record_array/array_observers.js