Permalink
Browse files

Merge pull request #19 from ghempton/master

Fix for modelCache sync issues in ModelArray
  • Loading branch information...
2 parents f548be3 + ab5b071 commit b956941e25ac5ab54a32ef1671d06778d80c817c @wycats wycats committed Jan 3, 2012
Showing with 45 additions and 2 deletions.
  1. +2 −2 packages/ember-data/lib/system/model_array.js
  2. +43 −0 packages/ember-data/tests/model_array_test.js
@@ -11,10 +11,10 @@ DS.ModelArray = SC.ArrayProxy.extend({
},
arrayDidChange: function(array, index, removed, added) {
- this._super(array, index, removed, added);
-
var modelCache = get(this, 'modelCache');
modelCache.replace(index, 0, Array(added));
+
+ this._super(array, index, removed, added);
},
arrayWillChange: function(array, index, removed, added) {
@@ -139,3 +139,46 @@ test("an AdapterPopulatedModelArray knows if it's loaded or not", function() {
equal(get(array, 'isLoaded'), false, "The array is not yet loaded");
});
+
+test("a model array that backs a collection view functions properly", function() {
+
+ var Person = DS.Model.extend();
+ var store = DS.Store.create();
+
+ store.load(Person, 5, { name: "Other Katz" });
+
+ var container = Ember.CollectionView.create({
+ classNameBindings: ['name'],
+ name: 'foo',
+ content: store.findAll(Person)
+ });
+
+ Ember.run(function() {
+ container.appendTo('#qunit-fixture');
+ });
+
+ function compareArrays() {
+ var modelArray = container.content;
+ var modelCache = modelArray.get('modelCache');
+ var content = modelArray.get('content');
+ for(var i = 0; i < content.length; i++) {
+ var model = modelCache.objectAt(i);
+ var clientId = content.objectAt(i);
+ equal(model && model.clientId, clientId, "The entries in the model cache should have matching client ids.");
+ }
+ }
+
+ compareArrays();
+
+ store.load(Person, 6, { name: "Scumbag Demon" });
+
+ compareArrays();
+
+ store.load(Person, 7, { name: "Lord British" });
+
+ compareArrays();
+
+ container.destroy();
+
+});
+

0 comments on commit b956941

Please sign in to comment.