mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-23 05:48:10 -05:00
Merge pull request #1440 from braddunbar/save-invalid
Fix #1433 - Do not save invalid models.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user