Permalink
Browse files

Only trigger a local 'destroy' event when fetchRelated fails; fixes #69

  • Loading branch information...
1 parent 723a698 commit 7169df159b353b4e5baabf0785d272c42c93154a @PaulUithol PaulUithol committed Feb 9, 2012
Showing with 6 additions and 6 deletions.
  1. +2 −2 backbone-relational.js
  2. +4 −4 test/tests.js
@@ -1004,7 +1004,7 @@
error: function() {
var args = arguments;
_.each( models, function( model ) {
- model.destroy();
+ model.trigger( 'destroy', model, model.collection, options );
options.error && options.error.apply( model, args );
});
},
@@ -1021,7 +1021,7 @@
var opts = _.defaults(
{
error: function() {
- model.destroy();
+ model.trigger( 'destroy', model, model.collection, options );
options.error && options.error.apply( model, arguments );
}
},
View
@@ -537,11 +537,11 @@ $(document).ready(function() {
ok( requests[ 0 ].url === '/animal/set/lion-2;zebra-2/' );
equal( zoo.get('animals').length, 2 );
- // Triggering the 'error' callback should destroy both of the fetched models
+ // Triggering the 'error' callback (some error occured during fetching) should trigger the 'destroy' event
+ // on both fetched models, but should NOT actually make 'delete' requests to the server!
+ var numRequests = window.requests.length;
requests[ 0 ].error();
- // Trigger the 'success' callback for both 'delete' calls to fire the 'destroy' event
- window.requests[ window.requests.length - 1 ].success();
- window.requests[ window.requests.length - 2 ].success();
+ ok( window.requests.length === numRequests, "An error occured when fetching, but no DELETE requests are made to the server while handling local cleanup." );
equal( zoo.get( 'animals' ).length, 0, "Both animals are destroyed" );
equal( errorCount, 2, "The error callback executed successfully for both models" );

0 comments on commit 7169df1

Please sign in to comment.