Skip to content

Commit

Permalink
Add test for models not being added to store until they get an id
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulUithol committed Jan 22, 2014
1 parent 77c3e1e commit 767bd49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backbone-relational.js
Expand Up @@ -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 {
Expand Down
17 changes: 15 additions & 2 deletions test/tests.js
Expand Up @@ -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 = [
Expand Down

0 comments on commit 767bd49

Please sign in to comment.