Skip to content

Commit

Permalink
Merge pull request #698 from alexgraul/master
Browse files Browse the repository at this point in the history
Fix for Issue #690
  • Loading branch information
tbranyen committed Oct 29, 2011
2 parents 8478567 + afc2d99 commit fbffb36
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,8 @@

// Wrap an optional error callback with a fallback error event.
var wrapError = function(onError, model, options) {
return function(resp) {
return function(model, resp) {
var resp = model === model ? resp : model;

This comment has been minimized.

Copy link
@plievone

plievone Oct 29, 2011

model === model will always be true, or do I miss some scoping detail...?

This comment has been minimized.

Copy link
@tbranyen

tbranyen Oct 29, 2011

Author Collaborator

Check out #690 and see if that sheds light on what this is.

if (onError) {
onError(model, resp, options);
} else {
Expand Down
16 changes: 16 additions & 0 deletions test/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,22 @@ $(document).ready(function() {
model.set({lastName: 'Hicks'});
});

test("Model: validate after save", function() {
var lastError, model = new Backbone.Model();
model.validate = function(attrs) {
if (attrs.admin) return "Can't change admin status.";
};
model.sync = function(method, model, options) {
options.success.call(this, {admin: true});
};
model.save(null, {error: function(model, error) {
console.log('erroring!');
lastError = error;
}});

equals(lastError, "Can't change admin status.");
});

test("Model: save", function() {
doc.save({title : "Henry V"});
equals(lastRequest[0], 'update');
Expand Down

0 comments on commit fbffb36

Please sign in to comment.