From aafbcb05e5f8fcda3c4952cd9228e8947902af13 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Thu, 2 Feb 2012 15:40:06 -0500 Subject: [PATCH] Fixes #917 -- reverts validate() behavior to never run on silent sets. --- backbone.js | 2 +- test/collection.js | 11 ++++------- test/model.js | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/backbone.js b/backbone.js index e8896567..b91bdc60 100644 --- a/backbone.js +++ b/backbone.js @@ -225,7 +225,7 @@ if (options.unset) for (attr in attrs) attrs[attr] = void 0; // Run validation. - if (!this._validate(attrs, options)) return false; + if (!options.silent && !this._validate(attrs, options)) return false; // Check for changes of `id`. if (this.idAttribute in attrs) this.id = attrs[this.idAttribute]; diff --git a/test/collection.js b/test/collection.js index 99759478..1705f57f 100644 --- a/test/collection.js +++ b/test/collection.js @@ -373,9 +373,7 @@ $(document).ready(function() { model: ValidatingModel }); var col = new ValidatingCollection(); - raises(function(){ - equal(col.create({"foo":"bar"}),false); - }); + equal(col.create({"foo":"bar"}), false); }); test("Collection: a failing create runs the error callback", function() { @@ -390,9 +388,8 @@ $(document).ready(function() { var flag = false; var callback = function(model, error) { flag = true; }; var col = new ValidatingCollection(); - raises(function(){ - col.create({"foo":"bar"}, { error: callback }); - }); + col.create({"foo":"bar"}, { error: callback }); + equal(flag, true); }); test("collection: initialize", function() { @@ -539,7 +536,7 @@ $(document).ready(function() { test("Collection: multiple copies of the same model", function() { var col = new Backbone.Collection(); var model = new Backbone.Model(); - raises(function() { col.add([model, model]) }); + raises(function() { col.add([model, model]); }); raises(function() { col.add([{id: 1}, {id: 1}]); }); }); diff --git a/test/model.js b/test/model.js index 346f2f09..1e951b53 100644 --- a/test/model.js +++ b/test/model.js @@ -392,9 +392,9 @@ $(document).ready(function() { equal(model.get('a'), 100); equal(lastError, undefined); result = model.set({admin: true}, {silent: true}); + equal(model.get('admin'), true); + result = model.set({a: 200, admin: false}); equal(lastError, "Can't change admin status."); - equal(model.get('admin'), void 0); - result = model.set({a: 200, admin: true}); equal(result, false); equal(model.get('a'), 100); });