From fdea29dfc812af03da22c13702f418b7c4d3af13 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Tue, 2 Jun 2015 14:06:50 -0400 Subject: [PATCH] Collection#add shouldn't parse a model instance Fixes #3636, but in a backwards compatible way. --- backbone.js | 6 +++--- test/collection.js | 20 +++----------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/backbone.js b/backbone.js index 53fb0872..945a5458 100644 --- a/backbone.js +++ b/backbone.js @@ -789,7 +789,7 @@ // the core operation for updating the data contained by the collection. set: function(models, options) { options = _.defaults({}, options, setOptions); - if (options.parse) models = this.parse(models, options); + if (options.parse && !this._isModel(models)) models = this.parse(models, options); var singular = !_.isArray(models); models = singular ? (models ? [models] : []) : models.slice(); var id, model, attrs, existing, sort; @@ -1776,7 +1776,7 @@ this._updateHash(this.location, fragment, options.replace); if (this.iframe && (fragment !== this.getHash(this.iframe.contentWindow))) { var iWindow = this.iframe.contentWindow; - + // Opening and closing the iframe tricks IE7 and earlier to push a // history entry on hash-tag change. When replace is true, we don't // want this. @@ -1784,7 +1784,7 @@ iWindow.document.open(); iWindow.document.close(); } - + this._updateHash(iWindow.location, fragment, options.replace); } diff --git a/test/collection.js b/test/collection.js index 507191e3..fa848186 100644 --- a/test/collection.js +++ b/test/collection.js @@ -561,31 +561,17 @@ }); - test("create with wait:true should not call collection.parse", 1, function() { - var collectionParseCalled = false; - - var Model = Backbone.Model.extend({ - sync: function (method, model, options) { - _.extend(options, {specialSync: true}); - return Backbone.Model.prototype.sync.call(this, method, model, options); - } - }); - + test("create with wait:true should not call collection.parse", 0, function() { var Collection = Backbone.Collection.extend({ - model: Model, url: '/test', parse: function () { - collectionParseCalled = true; + ok(false); } }); var collection = new Collection; - var success = function (model, response, options) { - equal(collectionParseCalled, false); - }; - - collection.create({}, {wait: true, success: success}); + collection.create({}, {wait: true}); this.ajaxSettings.success(); });