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

Commit c8c6687e by Bart Nagel

move error on non-function model validation function from validate() to DAO factory

Also add a test for it
1 parent 05a8ac72
......@@ -21,6 +21,12 @@ module.exports = (function() {
schemaDelimiter: ''
}, options || {})
// error check options
Utils._.each(options.validate, function(validator, validatorType) {
if (!Utils._.isFunction(validator))
throw new Error("Members of the validate option must be functions. Model: " + name + ", error with validate member " + validatorType)
})
this.name = name
if (!this.options.tableName) {
this.tableName = this.options.freezeTableName ? name : Utils.pluralize(name)
......
......@@ -271,8 +271,6 @@ module.exports = (function() {
// for each model validator for this DAO
Utils._.each(self.__options.validate, function(validator, validatorType) {
if (!Utils._.isFunction(validator))
throw new Error("Invalid model validator function: " + validatorType)
try {
validator.apply(self)
} catch (err) {
......
......@@ -70,6 +70,20 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
})
}.bind(this), 'Invalid DAO definition. Only one autoincrement field allowed.')
})
it('throws an error if a custom model-wide validation is not a function', function() {
Helpers.assertException(function() {
this.sequelize.define('Foo', {
field: {
type: Sequelize.INTEGER
}
}, {
validate: {
notFunction: 33
}
})
}.bind(this), 'Members of the validate option must be functions. Model: Foo, error with validate member notFunction')
})
})
describe('build', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!