Don't check uniqueness of blank values

This commit is contained in:
Fabien Franzen 2014-07-11 22:07:57 +02:00
parent 2dfef8cc7f
commit 5f1431aa05
2 changed files with 16 additions and 0 deletions

View File

@ -305,6 +305,7 @@ function validateCustom(attr, conf, err, done) {
* Uniqueness validator
*/
function validateUniqueness(attr, conf, err, done) {
if (blank(this[attr])) return done();
var cond = {where: {}};
cond.where[attr] = this[attr];

View File

@ -227,6 +227,21 @@ describe('validations', function () {
done(err);
});
});
it('should skip blank values', function (done) {
User.validatesUniquenessOf('email');
var u = new User({email: ' '});
Boolean(u.isValid(function (valid) {
valid.should.be.true;
u.save(function () {
var u2 = new User({email: null});
u2.isValid(function (valid) {
valid.should.be.true;
done();
});
});
})).should.be.false;
});
});
describe('format', function () {