Merge pull request #1440 from braddunbar/save-invalid

Fix #1433 - Do not save invalid models.
This commit is contained in:
Jeremy Ashkenas
2012-06-22 07:31:42 -07:00
2 changed files with 10 additions and 0 deletions

View File

@@ -367,6 +367,9 @@
return false;
}
// Do not persist invalid models.
if (!attrs && !this.isValid()) return false;
// After a successful server-side save, the client is (optionally)
// updated with the server-side state.
var model = this;

View File

@@ -847,4 +847,11 @@ $(document).ready(function() {
.destroy({ success: function(){ ok(true); }});
});
test("#1433 - Save: An invalid model cannot be persisted.", 1, function() {
var model = new Backbone.Model;
model.validate = function(){ return 'invalid'; };
model.sync = function(){ ok(false); };
strictEqual(model.save(), false);
});
});