mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-08 03:00:26 -04:00
Collection.add should fail if duplicate id/cid exists
This commit is contained in:
@@ -95,6 +95,25 @@ $(document).ready(function() {
|
||||
equals(atCol.last(), h);
|
||||
});
|
||||
|
||||
test("Collection: add model to collection twice", function() {
|
||||
try {
|
||||
// same id, different cid
|
||||
col.add({id: a.id, label: a.label});
|
||||
ok(false, "duplicate; expected add to fail");
|
||||
} catch (e) {
|
||||
equals(e.message, "Can't add the same model to a set twice,3");
|
||||
}
|
||||
try {
|
||||
// no id, same cid
|
||||
var a2 = new Backbone.Model({label: a.label});
|
||||
a2.cid = a.cid
|
||||
col.add(a2);
|
||||
ok(false, "duplicate; expected add to fail");
|
||||
} catch (e) {
|
||||
equals(e.message, "Can't add the same model to a set twice,3");
|
||||
}
|
||||
});
|
||||
|
||||
test("Collection: add model to multiple collections", function() {
|
||||
var counter = 0;
|
||||
var e = new Backbone.Model({id: 10, label : 'e'});
|
||||
|
||||
Reference in New Issue
Block a user