Permalink
Browse files

Add test for models not being added to store until they get an id

  • Loading branch information...
1 parent 77c3e1e commit 767bd49e41e4d2fed308cbe6c6ba057bdd080b2f @PaulUithol committed Jan 22, 2014
Showing with 16 additions and 3 deletions.
  1. +1 −1 backbone-relational.js
  2. +15 −2 test/tests.js
@@ -511,7 +511,7 @@
_.invoke( model.getRelations(), 'stopListening' );
var coll = this.getCollection( model );
- if ( coll.contains( model ) ) {
+ if ( coll.get( model ) ) {
coll.remove( model, options );
}
else {
View
@@ -722,12 +722,25 @@ $(document).ready(function() {
});
- test( "Model.collection is the first collection a Model is added to by an end-user (not it's Backbone.Store collection!)", function() {
- var person = new Person( { name: 'New guy' } );
+ test( "Model.collection is the first collection a Model is added to by an end-user (not its Backbone.Store collection!)", function() {
+ var person = new Person( { id: 5, name: 'New guy' } );
var personColl = new PersonCollection();
personColl.add( person );
ok( person.collection === personColl );
});
+
+ test( "Models don't get added to the store until the get an id", function() {
+ var storeColl = Backbone.Relational.store.getCollection( Node ),
+ node1 = new Node( { id: 1 } ),
+ node2 = new Node();
+
+ ok( storeColl.contains( node1 ) );
+ ok( !storeColl.contains( node2 ) );
+
+ node2.set( { id: 2 } );
+
+ ok( storeColl.contains( node1 ) );
+ });
test( "All models can be found after adding them to a Collection via 'Collection.reset'", function() {
var nodes = [

0 comments on commit 767bd49

Please sign in to comment.