Merge branch 'master' of github.com:documentcloud/backbone

This commit is contained in:
Jeremy Ashkenas
2010-11-18 09:43:01 -05:00
2 changed files with 25 additions and 1 deletions

View File

@@ -537,7 +537,7 @@
// hash indexes for `id` and `cid` lookups.
_remove : function(model, options) {
options || (options = {});
model = this.getByCid(model);
model = this.getByCid(model) || this.get(model);
if (!model) return null;
delete this._byId[model.id];
delete this._byCid[model.cid];

View File

@@ -70,6 +70,30 @@ $(document).ready(function() {
equals(col.length, 4);
equals(col.first(), d);
});
test("Collection: remove in multiple collections", function() {
var modelData = {
id : 5,
title : 'Othello'
};
var passed = false;
var e = new Backbone.Model(modelData);
var f = new Backbone.Model(modelData);
f.bind('remove', function() {
passed = true;
});
var colE = new Backbone.Collection([e]);
var colF = new Backbone.Collection([f]);
ok(e != f);
ok(colE.length == 1);
ok(colF.length == 1);
colE.remove(e);
equals(passed, false);
ok(colE.length == 0);
colF.remove(e);
ok(colF.length == 0);
equals(passed, true);
});
test("Collection: fetch", function() {
col.fetch();