Permalink
Browse files

Use serialized model as response to sync, instead of the model.

  • Loading branch information...
1 parent 0582ba5 commit 28b476065b726253307ae1606a748f9d77b2b46f @spiralman spiralman committed Jun 20, 2012
Showing with 27 additions and 3 deletions.
  1. +1 −1 backbone.localStorage-min.js
  2. +2 −2 backbone.localStorage.js
  3. +24 −0 tests/test.js

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -49,14 +49,14 @@ _.extend(Backbone.LocalStorage.prototype, {
this.localStorage().setItem(this.name+"-"+model.id, JSON.stringify(model));
this.records.push(model.id.toString());
this.save();
- return model;
+ return model.toJSON();
},
// Update a model by replacing its copy in `this.data`.
update: function(model) {
this.localStorage().setItem(this.name+"-"+model.id, JSON.stringify(model));
if (!_.include(this.records, model.id.toString())) this.records.push(model.id.toString()); this.save();
- return model;
+ return model.toJSON();
},
// Retrieve a model from `this.data` by id.
View
@@ -57,6 +57,30 @@ $(document).ready(function() {
equals(library.first().get('author'), 'William Shakespeare', 'verify author update');
});
+ test("should pass attributes to parse after creating", function() {
+ var book = new Backbone.Model(attrs);
+ book.collection = library;
+
+ book.parse = function(savedAttrs) {
+ equal(savedAttrs.title, attrs.title, 'attributes passed to parse')
+ equal(savedAttrs.author, attrs.author, 'attributes passed to parse')
+ equal(savedAttrs.length, attrs.length, 'attributes passed to parse')
+ };
+
+ book.save();
+ });
+
+ test("should pass attributes to parse after updating", function() {
+ var book = library.create(attrs);
+
+ book.parse = function(savedAttrs) {
+ equal(savedAttrs.title, attrs.title, 'attributes passed to parse')
+ equal(savedAttrs.author, attrs.author, 'attributes passed to parse')
+ equal(savedAttrs.length, attrs.length, 'attributes passed to parse')
+ };
+
+ book.save();
+ });
test("should store model id inside collection", function() {
var book = library.create(attrs);

0 comments on commit 28b4760

Please sign in to comment.