Skip to content

Commit

Permalink
Ensure that fetch calls update if only {add: true} option is passed, …
Browse files Browse the repository at this point in the history
…instead of calling reset
  • Loading branch information
fabiomcosta committed Dec 20, 2012
1 parent 7f29c8c commit 6971da0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backbone.js
Expand Up @@ -859,7 +859,7 @@
var collection = this; var collection = this;
var success = options.success; var success = options.success;
options.success = function(resp, status, xhr) { options.success = function(resp, status, xhr) {
var method = options.update ? 'update' : 'reset'; var method = (options.update || options.add) ? 'update' : 'reset';
collection[method](resp, options); collection[method](resp, options);
if (success) success(collection, resp, options); if (success) success(collection, resp, options);
}; };
Expand Down
13 changes: 13 additions & 0 deletions test/collection.js
Expand Up @@ -407,6 +407,19 @@ $(document).ready(function() {
equal(counter, 1); equal(counter, 1);
}); });


test("ensure fetch calls 'update' if only {add: true} option is passed", 1, function() {
var collection = new Backbone.Collection;
var counter = 0;
collection.update = function(models) {
counter++;
return this;
};
collection.url = '/test';
collection.fetch({add: true});
this.syncArgs.options.success([]);
equal(counter, 1);
});

test("create", 4, function() { test("create", 4, function() {
var collection = new Backbone.Collection; var collection = new Backbone.Collection;
collection.url = '/test'; collection.url = '/test';
Expand Down

0 comments on commit 6971da0

Please sign in to comment.