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 e234a683
authored
Oct 17, 2013
by
thanpolas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
re-enable synchronous model validators
1 parent
518baccc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
1 deletions
lib/dao-validator.js
test/dao.validations.test.js
lib/dao-validator.js
View file @
e234a68
...
@@ -73,6 +73,7 @@ var validateModel = function() {
...
@@ -73,6 +73,7 @@ var validateModel = function() {
this
.
chainer
.
add
(
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
this
.
chainer
.
add
(
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
next
=
function
(
err
)
{
var
next
=
function
(
err
)
{
if
(
err
)
{
if
(
err
)
{
var
error
=
{}
var
error
=
{}
error
[
validatorType
]
=
[
err
]
error
[
validatorType
]
=
[
err
]
...
@@ -137,8 +138,33 @@ var prepareValidationOfAttribute = function(value, details, validatorType, optio
...
@@ -137,8 +138,33 @@ var prepareValidationOfAttribute = function(value, details, validatorType, optio
if
(
typeof
details
===
'function'
)
{
if
(
typeof
details
===
'function'
)
{
// it is a custom validator function?
// it is a custom validator function?
isCustomValidator
=
true
isCustomValidator
=
true
var
callArgs
=
[]
var
validatorArity
=
details
.
length
var
omitValue
=
!!
(
options
||
{}).
omitValue
if
(
!
omitValue
)
{
callArgs
.
push
(
value
)
}
// check if validator is async and requires a callback
var
isAsync
=
omitValue
&&
validatorArity
===
1
||
!
omitValue
&&
validatorArity
===
2
validatorFunction
=
function
(
next
)
{
validatorFunction
=
function
(
next
)
{
details
.
apply
(
this
.
model
,
((
options
||
{}).
omitValue
)
?
[
next
]
:
[
value
,
next
])
if
(
isAsync
)
{
callArgs
.
push
(
next
)
}
try
{
details
.
apply
(
this
.
model
,
callArgs
)
}
catch
(
ex
)
{
return
next
(
ex
.
message
)
}
if
(
!
isAsync
)
{
next
()
}
}.
bind
(
this
)
}.
bind
(
this
)
}
else
{
}
else
{
// it is a validator module function?
// it is a validator module function?
...
...
test/dao.validations.test.js
View file @
e234a68
/* jshint expr:true */
var
chai
=
require
(
'chai'
)
var
chai
=
require
(
'chai'
)
,
expect
=
chai
.
expect
,
expect
=
chai
.
expect
,
Sequelize
=
require
(
__dirname
+
'/../index'
)
,
Sequelize
=
require
(
__dirname
+
'/../index'
)
...
@@ -571,6 +572,43 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -571,6 +572,43 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
})
})
})
})
it
(
'validates a model with no async callback'
,
function
(
done
)
{
var
Foo
=
this
.
sequelize
.
define
(
'Foo'
+
config
.
rand
(),
{
field1
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
true
},
field2
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
true
}
},
{
validate
:
{
xnor
:
function
()
{
if
((
this
.
field1
===
null
)
===
(
this
.
field2
===
null
))
{
throw
new
Error
(
'xnor failed'
)
}
}
}
})
Foo
.
build
({
field1
:
null
,
field2
:
null
})
.
validate
()
.
success
(
function
(
errors
)
{
expect
(
errors
).
not
.
to
.
be
.
null
expect
(
errors
).
to
.
deep
.
equal
({
'xnor'
:
[
'xnor failed'
]
})
Foo
.
build
({
field1
:
33
,
field2
:
null
})
.
validate
()
.
success
(
function
(
errors
)
{
expect
(
errors
).
not
.
exist
done
()
})
})
})
it
(
'validates model with a validator whose arg is an Array successfully twice in a row'
,
function
(
done
){
it
(
'validates model with a validator whose arg is an Array successfully twice in a row'
,
function
(
done
){
var
Foo
=
this
.
sequelize
.
define
(
'Foo'
+
config
.
rand
(),
{
var
Foo
=
this
.
sequelize
.
define
(
'Foo'
+
config
.
rand
(),
{
bar
:
{
bar
:
{
...
...
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