Merge pull request #3875 from Flamefork/3871-set-parse-undefined

Fixed Collection#set regression when parse returns falsy value
This commit is contained in:
Justin Ridgewell
2015-12-01 10:25:23 -05:00
2 changed files with 9 additions and 1 deletions

View File

@@ -824,7 +824,7 @@
if (options.parse && !this._isModel(models)) models = this.parse(models, options);
var singular = !_.isArray(models);
models = singular ? [models] : models.slice();
models = singular ? (models ? [models] : []) : models.slice();
var at = options.at;
if (at != null) at = +at;

View File

@@ -1817,4 +1817,12 @@
model.trigger('change');
});
QUnit.test('#3871 - falsy parse result creates empty collection', function(assert) {
var collection = new (Backbone.Collection.extend({
parse: function (data, options) {}
}));
collection.set('', { parse: true });
assert.equal(collection.length, 0);
});
})();