#1386 Allow empty values when allowBlank is true
This commit is contained in:
parent
6a1b55568c
commit
82a8e3d9a1
|
@ -709,7 +709,7 @@ var defaultMessages = {
|
|||
*/
|
||||
function nullCheck(attr, conf, err) {
|
||||
// First determine if attribute is defined
|
||||
if (typeof this[attr] === 'undefined') {
|
||||
if (typeof this[attr] === 'undefined' || this[attr] === '') {
|
||||
if (!conf.allowBlank) {
|
||||
err('blank');
|
||||
}
|
||||
|
|
|
@ -755,6 +755,25 @@ describe('validations', function() {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('passes with an empty value when allowBlank option is true', function(done) {
|
||||
User.validatesInclusionOf('gender', {in: ['male', 'female'], allowBlank: true});
|
||||
User.create({gender: ''}, done);
|
||||
});
|
||||
|
||||
it('fails with an empty value when allowBlank option is false', function(done) {
|
||||
User.validatesInclusionOf('gender', {in: ['male', 'female'], allowBlank: false});
|
||||
User.create({gender: ''}, function(err) {
|
||||
err.should.be.instanceOf(ValidationError);
|
||||
getErrorDetails(err)
|
||||
.should.equal('`gender` is blank (value: "").');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
function getErrorDetails(err) {
|
||||
return err.message.replace(/^.*Details: /, '');
|
||||
}
|
||||
});
|
||||
|
||||
describe('exclusion', function() {
|
||||
|
|
Loading…
Reference in New Issue