ampersand-collection
Advanced tools
Comparing version 1.3.15 to 1.3.16
@@ -267,2 +267,3 @@ var BackboneEvents = require('backbone-events-standalone'); | ||
if (this.isModel(attrs)) { | ||
if (!attrs.collection) attrs.collection = this; | ||
return attrs; | ||
@@ -272,3 +273,6 @@ } else { | ||
options.collection = this; | ||
return new this.model(attrs, options); | ||
var model = new this.model(attrs, options); | ||
if (!model.validationError) return model; | ||
this.trigger('invalid', this, model.validationError, options); | ||
return false; | ||
} | ||
@@ -275,0 +279,0 @@ }, |
{ | ||
"name": "ampersand-collection", | ||
"version": "1.3.15", | ||
"version": "1.3.16", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -5,0 +5,0 @@ "bugs": { |
@@ -325,1 +325,32 @@ var test = require('tape'); | ||
}); | ||
test('add with validate:true enforces validation', function (t) { | ||
t.plan(5); | ||
var Model = State.extend({ | ||
idAttribute: '_id', | ||
props: { | ||
_id: 'string' | ||
}, | ||
validate: function (attributes) { | ||
return 'fail'; | ||
} | ||
}); | ||
var C = Collection.extend({ | ||
model: Model | ||
}); | ||
var c = new C(); | ||
c.on('invalid', function (collection, error, options) { | ||
t.equal(c, collection); | ||
t.equal(error, 'fail'); | ||
t.equal(options.validate, true); | ||
}); | ||
var result = c.add({_id: 'a'}, {validate: true}); | ||
t.equal(c.length, 0); | ||
t.equal(result, false); | ||
t.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
39696
624
0