Fixes #917 -- reverts validate() behavior to never run on silent sets.

This commit is contained in:
Jeremy Ashkenas
2012-02-02 15:40:06 -05:00
parent ad870b256c
commit aafbcb05e5
3 changed files with 7 additions and 10 deletions

View File

@@ -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];

View File

@@ -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}]); });
});

View File

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