[Pkg-javascript-commits] [backbone] 44/281: fix for wrapped errors inside success callbacks on save, issue #690

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:01:55 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.9.0
in repository backbone.

commit 970ce0762c3627443624f171505648ae3d30b281
Author: Alex Graul <alex.graul at guardian.co.uk>
Date:   Sat Oct 29 15:51:41 2011 -0400

    fix for wrapped errors inside success callbacks on save, issue #690
---
 backbone.js   |  3 ++-
 test/model.js | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/backbone.js b/backbone.js
index a7dd404..55c2c2b 100644
--- a/backbone.js
+++ b/backbone.js
@@ -1147,7 +1147,8 @@
 
   // Wrap an optional error callback with a fallback error event.
   var wrapError = function(onError, model, options) {
-    return function(resp) {
+    return function(first, second) {
+      var resp = first === model ? second : first;
       if (onError) {
         onError(model, resp, options);
       } else {
diff --git a/test/model.js b/test/model.js
index 7ad0d71..395b9f7 100644
--- a/test/model.js
+++ b/test/model.js
@@ -267,6 +267,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');

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list