Skip to content

Commit

Permalink
Ensure fetch'd data is only parsed once
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed May 30, 2015
1 parent 415c3a7 commit 13de636
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1611,4 +1611,28 @@
equal(c.get(1).get('attr'), 'test');
});

test("fetch data is only parsed once", 3, function() {
var modelParse = 0;
var collectionParse = 0;
var Collection = Backbone.Collection.extend({
url: '/test',
model: Backbone.Model.extend({
parse: function(model) {
modelParse++;
return model.model;
}
}),
parse: function(models) {
collectionParse++;
return models.models;
}
});
var c = new Collection();
c.fetch();
this.ajaxSettings.success({models: [{model: {id: 1, attr: 'test'} }] });
equal(modelParse, 1);
equal(collectionParse, 1);
equal(c.get(1).get('attr'), 'test');
});

})();

0 comments on commit 13de636

Please sign in to comment.