Skip to content

Commit

Permalink
Fixes #917 -- reverts validate() behavior to never run on silent sets.
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Feb 2, 2012
1 parent ad870b2 commit aafbcb0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
11 changes: 4 additions & 7 deletions test/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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}]); });
});

Expand Down
4 changes: 2 additions & 2 deletions test/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit aafbcb0

Please sign in to comment.