From 13de636df1862fb331735e5d019e9ba8c01430d0 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Fri, 29 May 2015 21:11:45 -0400 Subject: [PATCH] Ensure fetch'd data is only parsed once --- test/collection.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/collection.js b/test/collection.js index 9b46aa7be..2cee05d40 100644 --- a/test/collection.js +++ b/test/collection.js @@ -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'); + }); + })();