Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Take into account 0.9.9 update:true in fetch

  • Loading branch information...
commit 702ac22d2c4ee6bfd7753b27869fa5f244fc783a 1 parent 2bb29bd
@ggozad authored
View
6 backbone.cachingsync.js
@@ -64,10 +64,12 @@
wp = wrapped('read', collection, options).done(function (models) {
_.each(models, function (model) { burry.set(model.id, model); });
- burry.set('__ids__', _.pluck(models, 'id'));
- if (!options.add) {
+ if (options.update) {
+ collection.update(models, options);
+ } else {
collection.reset(models);
}
+ burry.set('__ids__', _.pluck(collection.models, 'id'));
});
if (typeof ids !== 'undefined') {
View
17 tests/specs/backbone.cachingsync_spec.js
@@ -75,6 +75,19 @@
expect(ajax).toHaveBeenCalled();
expect(collection2.models[0].attributes).toEqual({id: 1, foo: 'bar'});
expect(collection2.models[1].attributes).toEqual({id: 2, bar: 'foo'});
+ });
+
+ it('it allows for {update: true} option in a fetch and updates without a reset', function () {
+
+ // In the beginning, we have no cache.
+ collection = new Collection();
+ ajax = spyOn($, 'ajax').andCallFake(function () {
+ return $.Deferred()
+ .resolve([{id: 1, foo: 'bar'}, {id: 2, bar: 'foo'}])
+ .promise();
+ });
+ p = collection.fetch();
+ expect(burry.get('__ids__')).toEqual([1, 2]);
// Make sure fetch respects the add=true option.
ajax.andCallFake(function () {
@@ -83,10 +96,12 @@
.promise();
});
collection = new Collection([{id: 3, foobar: 'foobar'}]);
- collection.fetch({add: true});
+ collection.fetch({update: true, add: true, remove: false});
+ expect(burry.get('__ids__')).toEqual([3, 1, 2]);
});
+
it('caches a create on a model', function () {
model = new Model({foo: 'bar'});
ajax = spyOn($, 'ajax').andCallFake(function (req) {
Please sign in to comment.
Something went wrong with that request. Please try again.