不要怂,就是干,撸起袖子干!

Commit adce84fb by Jan Aagaard Meier

Merge pull request #634 from tremby/allowNull-skip-validations-test

add test for skipping validations when value is null and allowNull is true
2 parents b67f4075 02e8dddc
Showing with 24 additions and 0 deletions
......@@ -282,5 +282,29 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
var successfulUser = User.build({ name : "2" })
expect(successfulUser.validate()).toBeNull()
})
it('skips other validations if allowNull is true and the value is null', function() {
var User = this.sequelize.define('User' + Math.random(), {
age: {
type: Sequelize.INTEGER,
allowNull: true,
validate: {
min: { args: 0, msg: 'must be positive' }
}
}
})
var failingUser = User.build({ age: -1 })
, errors = failingUser.validate()
expect(errors).not.toBeNull(null)
expect(errors).toEqual({ age: ['must be positive'] })
var successfulUser1 = User.build({ age: null })
expect(successfulUser1.validate()).toBeNull()
var successfulUser2 = User.build({ age: 1 })
expect(successfulUser2.validate()).toBeNull()
})
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!