Merge pull request #409 from billinghamj/master
Fixed nullCheck in validations for undefined attributes
This commit is contained in:
commit
577def97f8
|
@ -589,8 +589,7 @@ var defaultMessages = {
|
|||
};
|
||||
|
||||
function nullCheck(attr, conf, err) {
|
||||
var isNull = this[attr] === null || !(attr in this);
|
||||
if (isNull) {
|
||||
if (this[attr] == null) {
|
||||
if (!conf.allowNull) {
|
||||
err('null');
|
||||
}
|
||||
|
|
|
@ -387,6 +387,30 @@ describe('validations', function () {
|
|||
describe('format', function () {
|
||||
it('should validate format');
|
||||
it('should overwrite default blank message with custom format message');
|
||||
|
||||
it('should skip missing values when allowing null', function () {
|
||||
User.validatesFormatOf('email', { with: /^\S+@\S+\.\S+$/, allowNull: true });
|
||||
var u = new User({});
|
||||
u.isValid().should.be.true;
|
||||
});
|
||||
|
||||
it('should skip null values when allowing null', function () {
|
||||
User.validatesFormatOf('email', { with: /^\S+@\S+\.\S+$/, allowNull: true });
|
||||
var u = new User({ email: null });
|
||||
u.isValid().should.be.true;
|
||||
});
|
||||
|
||||
it('should not skip missing values', function () {
|
||||
User.validatesFormatOf('email', { with: /^\S+@\S+\.\S+$/ });
|
||||
var u = new User({});
|
||||
u.isValid().should.be.false;
|
||||
});
|
||||
|
||||
it('should not skip null values', function () {
|
||||
User.validatesFormatOf('email', { with: /^\S+@\S+\.\S+$/ });
|
||||
var u = new User({ email: null });
|
||||
u.isValid().should.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
describe('numericality', function () {
|
||||
|
|
Loading…
Reference in New Issue