mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-08 03:00:26 -04:00
This commit is contained in:
@@ -530,7 +530,7 @@
|
||||
if (!(model instanceof Backbone.Model)) {
|
||||
var attrs = model;
|
||||
model = new this.model(null, {collection: coll});
|
||||
if (!model.set(attrs)) return false;
|
||||
if (!model.set(attrs, options)) return false;
|
||||
} else {
|
||||
model.collection = coll;
|
||||
}
|
||||
|
||||
@@ -233,6 +233,22 @@ $(document).ready(function() {
|
||||
equals(col.create({"foo":"bar"}),false);
|
||||
});
|
||||
|
||||
test("Collection: a failing create runs the error callback", function() {
|
||||
var ValidatingModel = Backbone.Model.extend({
|
||||
validate: function(attrs) {
|
||||
return "fail";
|
||||
}
|
||||
});
|
||||
var ValidatingCollection = Backbone.Collection.extend({
|
||||
model: ValidatingModel
|
||||
});
|
||||
var flag = false;
|
||||
var callback = function(model, error) { flag = true; };
|
||||
var col = new ValidatingCollection();
|
||||
col.create({"foo":"bar"}, { error: callback });
|
||||
equals(flag, true);
|
||||
});
|
||||
|
||||
test("collection: initialize", function() {
|
||||
var Collection = Backbone.Collection.extend({
|
||||
initialize: function() {
|
||||
|
||||
Reference in New Issue
Block a user