Skip to content

Commit

Permalink
A wrapped sync would return json to create not a model
Browse files Browse the repository at this point in the history
  • Loading branch information
ggozad committed Jan 4, 2013
1 parent 971f53f commit 2bb29bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions backbone.cachingsync.js
Expand Up @@ -87,12 +87,12 @@
// the model (and potentially its collection) is cached.
function create (model, options) {
return wrapped('create', model, options)
.done(function (newmodel) {
burry.set(newmodel.id, newmodel.attributes);
.done(function (attrs) {
burry.set(attrs[model.idAttribute], attrs);
if (model.collection)
burry.set('__ids__', _(model.collection.models).chain()
.pluck('id')
.union([newmodel.id])
.union([attrs[model.idAttribute]])
.without(undefined).value());

}).promise();
Expand Down
10 changes: 5 additions & 5 deletions tests/specs/backbone.cachingsync_spec.js
Expand Up @@ -91,7 +91,7 @@
model = new Model({foo: 'bar'});
ajax = spyOn($, 'ajax').andCallFake(function (req) {
return $.Deferred()
.resolve(new Model({id: 1, foo: 'bar'}))
.resolve({id: 1, foo: 'bar'})
.promise();
});
model.save();
Expand All @@ -103,7 +103,7 @@
collection = new Collection([{id: 1, bar: 'foo'}, {foo: 'bar'}]);
ajax = spyOn($, 'ajax').andCallFake(function (req) {
return $.Deferred()
.resolve(new Model({id: 2, foobar: 'barfoo'}))
.resolve({id: 2, foobar: 'barfoo'})
.promise();
});
collection.create({foobar: 'barfoo'});
Expand Down Expand Up @@ -144,13 +144,13 @@
model = new Model({foo: 'bar'});
ajax = spyOn($, 'ajax').andCallFake(function (req) {
return $.Deferred()
.resolve(new Model({id: 1, foo: 'bar'}))
.resolve({id: 1, foo: 'bar'})
.promise();
});
model.save();
ajax.andCallFake(function (req) {
return $.Deferred()
.resolve(new Model({id: 1, foo: 'bar', bar: 'foo'}))
.resolve({id: 1, foo: 'bar', bar: 'foo'})
.promise();
});
model.destroy();
Expand All @@ -163,7 +163,7 @@
model.sync = Backbone.cachingSync(Backbone.sync, 'testingttl', 10);
ajax = spyOn($, 'ajax').andCallFake(function (req) {
return $.Deferred()
.resolve(new Model({id: 1, foo: 'bar'}))
.resolve({id: 1, foo: 'bar'})
.promise();
});
model.save();
Expand Down

0 comments on commit 2bb29bd

Please sign in to comment.