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 c6bd7b2e
authored
Apr 09, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged and modified PR #1610. Added test for using promises in validations, thanks to @callumacrae
1 parent
03e564f1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
test/dao.validations.test.js
test/dao.validations.test.js
View file @
c6bd7b2
...
...
@@ -548,6 +548,37 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
})
})
it
(
'supports promises with custom validation methods'
,
function
(
done
)
{
var
self
=
this
,
User
=
this
.
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
{
type
:
Sequelize
.
STRING
,
validate
:
{
customFn
:
function
(
val
)
{
return
User
.
findAll
()
.
then
(
function
()
{
if
(
val
===
"error"
)
{
throw
new
Error
(
"Invalid username"
)
}
})
}
}
}
})
User
.
sync
().
success
(
function
()
{
User
.
build
({
name
:
"error"
}).
validate
().
success
(
function
(
error
)
{
expect
(
error
).
to
.
be
.
an
.
instanceOf
(
self
.
sequelize
.
ValidationError
)
expect
(
error
.
name
[
0
].
message
).
to
.
equal
(
"Invalid username"
)
User
.
build
({
name
:
"no error"
}).
validate
().
success
(
function
()
{
expect
(
arguments
).
to
.
have
.
length
(
0
)
done
()
})
})
})
})
it
(
'skips other validations if allowNull is true and the value is null'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
age
:
{
...
...
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