Permalink
Browse files

Ensure that fetch calls update if only {add: true} option is passed, …

…instead of calling reset
  • Loading branch information...
1 parent 7f29c8c commit 6971da0514e8447f974c179b45c347f635794691 @fabiomcosta committed Dec 20, 2012
Showing with 14 additions and 1 deletion.
  1. +1 −1 backbone.js
  2. +13 −0 test/collection.js
View
@@ -859,7 +859,7 @@
var collection = this;
var success = options.success;
options.success = function(resp, status, xhr) {
- var method = options.update ? 'update' : 'reset';
+ var method = (options.update || options.add) ? 'update' : 'reset';
collection[method](resp, options);
if (success) success(collection, resp, options);
};
View
@@ -407,6 +407,19 @@ $(document).ready(function() {
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() {
var collection = new Backbone.Collection;
collection.url = '/test';

0 comments on commit 6971da0

Please sign in to comment.