Merge pull request #698 from alexgraul/master

Fix for Issue #690
This commit is contained in:
Tim Branyen
2011-10-29 13:21:15 -07:00
2 changed files with 18 additions and 1 deletions

View File

@@ -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;
if (onError) {
onError(model, resp, options);
} else {

View File

@@ -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');