Permalink
Browse files

Fixed bug where record changes that only needed to resort a list woul…

…d not clear the REcordArray cache causing the list to display incorrectly.
  • Loading branch information...
1 parent e9b957a commit 699d8034aff4026f3f0dd3e8a6535e057db9ac68 Charles Jolley committed Jan 20, 2010
View
6 frameworks/datastore/system/record_array.js
@@ -531,6 +531,12 @@ SC.RecordArray = SC.Object.extend(SC.Enumerable, SC.Array,
// only resort and update if we did change
if (didChange) {
+
+ // storeKeys must be a new instance because orderStoreKeys() works on it
+ if (storeKeys && (storeKeys===oldStoreKeys)) {
+ storeKeys = storeKeys.copy();
+ }
+
storeKeys = SC.Query.orderStoreKeys(storeKeys, query, store);
if (SC.compare(oldStoreKeys, storeKeys) !== 0){
this.set('storeKeys', SC.clone(storeKeys)); // replace content
View
43 frameworks/datastore/tests/system/record_array/flush.js
@@ -129,6 +129,49 @@ test("calling storeDidChangeStoreKeys() to remove a record", function() {
});
+// ..........................................................
+// SPECIAL CASES
+//
+
+var json2, foo, bar ;
+
+module("SC.RecordArray core methods", {
+ setup: function() {
+ // setup dummy store
+ store = SC.Store.create();
+
+ storeKey = SC.Record.storeKeyFor('foo');
+ json = { guid: "foo", name: "foo" };
+ store.writeDataHash(storeKey, json, SC.Record.READY_CLEAN);
+ foo = store.materializeRecord(storeKey);
+ equals(foo.get('name'), 'foo', 'record should have json');
+
+ storeKey = SC.Record.storeKeyFor('bar');
+ json2 = { guid: "bar", name: "bar" };
+ store.writeDataHash(storeKey, json2, SC.Record.READY_CLEAN);
+ bar = store.materializeRecord(storeKey);
+ equals(bar.get('name'), 'bar', 'record should have json');
+
+ // get record array.
+ query = SC.Query.create({ recordType: SC.Record, orderBy: 'name' });
+ recs = store.find(query);
+ }
+});
+
+test("local query should notify changes", function() {
+
+ // note: important to retrieve records from RecordArray first to prime
+ // any cache
+ same(recs.mapProperty('id'), ['bar', 'foo'], 'PRECOND - bar should appear before foo');
+
+ SC.stopIt = YES;
+
+ SC.RunLoop.begin();
+ bar.set('name', 'zzbar');
+ SC.RunLoop.end(); // should resort record array
+
+ same(recs.mapProperty('id'), ['foo', 'bar'], 'order of records should change');
+});

0 comments on commit 699d803

Please sign in to comment.