Skip to content

Instantly share code, notes, and snippets.

@jameshartig
Last active August 29, 2015 14:16
Show Gist options
  • Save jameshartig/b954f60abe3b85bac7c1 to your computer and use it in GitHub Desktop.
Save jameshartig/b954f60abe3b85bac7c1 to your computer and use it in GitHub Desktop.
test('Do not allow duplicate models (with nonstandard id) to be `add`ed or `set`', function() {
var Stooge = Backbone.Model.extend({
parse: function(a) {
var attrs = {};
attrs._id = a.__id;
return attrs;
}
});
Stooge.prototype.idAttribute = '_id';
var StoogeCollection = Backbone.Collection.extend({model: Stooge}),
c = new StoogeCollection();
c.add([{__id: 1}, {__id: 1}]);
equal(c.length, 1);
equal(c.models.length, 1);
c.set([{__id: 1}, {__id: 1}]);
equal(c.length, 1);
equal(c.models.length, 1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment