Fix multi-property validation definitions

Fixes #291, as introduced by me ...
https://github.com/strongloop/loopback-datasource-juggler/commit/6fae8c7
27759256157bf7ccd82e04ee372a59088
This commit is contained in:
Fabien Franzen 2014-09-05 18:00:11 +02:00
parent aea2f64181
commit a66e612c87
2 changed files with 14 additions and 7 deletions

View File

@ -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() {

View File

@ -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;
});