Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 39c0b628
authored
May 24, 2013
by
Bart Nagel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throw an error on model validator with same name as field
Plus a test for that
1 parent
c8c6687e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
lib/dao-factory.js
spec/dao-factory.spec.js
lib/dao-factory.js
View file @
39c0b62
...
@@ -23,6 +23,8 @@ module.exports = (function() {
...
@@ -23,6 +23,8 @@ module.exports = (function() {
// error check options
// error check options
Utils
.
_
.
each
(
options
.
validate
,
function
(
validator
,
validatorType
)
{
Utils
.
_
.
each
(
options
.
validate
,
function
(
validator
,
validatorType
)
{
if
(
Utils
.
_
.
contains
(
Utils
.
_
.
keys
(
attributes
),
validatorType
))
throw
new
Error
(
"A model validator function must not have the same name as a field. Model: "
+
name
+
", field/validation name: "
+
validatorType
)
if
(
!
Utils
.
_
.
isFunction
(
validator
))
if
(
!
Utils
.
_
.
isFunction
(
validator
))
throw
new
Error
(
"Members of the validate option must be functions. Model: "
+
name
+
", error with validate member "
+
validatorType
)
throw
new
Error
(
"Members of the validate option must be functions. Model: "
+
name
+
", error with validate member "
+
validatorType
)
})
})
...
...
spec/dao-factory.spec.js
View file @
39c0b62
...
@@ -84,6 +84,20 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
...
@@ -84,6 +84,20 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
})
})
}.
bind
(
this
),
'Members of the validate option must be functions. Model: Foo, error with validate member notFunction'
)
}.
bind
(
this
),
'Members of the validate option must be functions. Model: Foo, error with validate member notFunction'
)
})
})
it
(
'throws an error if a custom model-wide validation has the same name as a field'
,
function
()
{
Helpers
.
assertException
(
function
()
{
this
.
sequelize
.
define
(
'Foo'
,
{
field
:
{
type
:
Sequelize
.
INTEGER
}
},
{
validate
:
{
field
:
function
()
{}
}
})
}.
bind
(
this
),
'A model validator function must not have the same name as a field. Model: Foo, field/validation name: field'
)
})
})
})
describe
(
'build'
,
function
()
{
describe
(
'build'
,
function
()
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment