Merge pull request #292 from fabien/fix/refactor-validations
Fix multi-property validation definitions
This commit is contained in:
commit
b364a57cf7
|
@ -641,13 +641,14 @@ function configure(cls, validation, args, opts) {
|
|||
conf.customValidator = args.pop();
|
||||
}
|
||||
conf.validation = validation;
|
||||
var attr = args[0];
|
||||
if (typeof attr === 'string') {
|
||||
var validation = extend({}, conf);
|
||||
validation.options = opts || {};
|
||||
cls.validations[attr] = cls.validations[attr] || [];
|
||||
cls.validations[attr].push(validation);
|
||||
}
|
||||
args.forEach(function (attr) {
|
||||
if (typeof attr === 'string') {
|
||||
var validation = extend({}, conf);
|
||||
validation.options = opts || {};
|
||||
cls.validations[attr] = cls.validations[attr] || [];
|
||||
cls.validations[attr].push(validation);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function Errors() {
|
||||
|
|
|
@ -145,9 +145,15 @@ describe('validations', function () {
|
|||
|
||||
it('should validate presence', function () {
|
||||
User.validatesPresenceOf('name', 'email');
|
||||
|
||||
var validations = User.validations;
|
||||
validations.name.should.eql([{validation: 'presence', options: {}}]);
|
||||
validations.email.should.eql([{validation: 'presence', options: {}}]);
|
||||
|
||||
var u = new User;
|
||||
u.isValid().should.not.be.true;
|
||||
u.name = 1;
|
||||
u.isValid().should.not.be.true;
|
||||
u.email = 2;
|
||||
u.isValid().should.be.true;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue