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:
parent
aea2f64181
commit
a66e612c87
|
@ -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