From a66e612c873f390f6854fdc887bd8e2878dc0759 Mon Sep 17 00:00:00 2001 From: Fabien Franzen Date: Fri, 5 Sep 2014 18:00:11 +0200 Subject: [PATCH] Fix multi-property validation definitions Fixes #291, as introduced by me ... https://github.com/strongloop/loopback-datasource-juggler/commit/6fae8c7 27759256157bf7ccd82e04ee372a59088 --- lib/validations.js | 15 ++++++++------- test/validations.test.js | 6 ++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/validations.js b/lib/validations.js index 62d91dbc..3d2e0849 100644 --- a/lib/validations.js +++ b/lib/validations.js @@ -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() { diff --git a/test/validations.test.js b/test/validations.test.js index 97ee49fe..4c83e682 100644 --- a/test/validations.test.js +++ b/test/validations.test.js @@ -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; });