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 6d79a939
authored
Feb 06, 2014
by
Thanasis Polychronakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
indent changes based on new code updates
1 parent
9c99552e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
14 deletions
lib/dao-validator.js
test/dao.validations.test.js
lib/dao-validator.js
View file @
6d79a93
...
...
@@ -27,16 +27,16 @@ DaoValidator.prototype.validate = function() {
emitter
.
emit
(
'success'
)
})
.
error
(
function
(
err
)
{
var
error
=
new
Error
(
'Validation error'
)
error
[
DaoValidator
.
RAW_KEY_NAME
]
=
[]
var
error
=
new
Error
(
'Validation error'
)
error
[
DaoValidator
.
RAW_KEY_NAME
]
=
[]
Utils
.
_
.
each
(
err
,
function
(
value
)
{
error
[
DaoValidator
.
RAW_KEY_NAME
].
push
(
value
[
DaoValidator
.
RAW_KEY_NAME
])
delete
value
[
DaoValidator
.
RAW_KEY_NAME
]
Utils
.
_
.
extend
(
error
,
value
)
error
[
DaoValidator
.
RAW_KEY_NAME
].
push
(
value
[
DaoValidator
.
RAW_KEY_NAME
])
delete
value
[
DaoValidator
.
RAW_KEY_NAME
]
Utils
.
_
.
extend
(
error
,
value
)
})
emitter
.
emit
(
'success'
,
error
)
emitter
.
emit
(
'success'
,
error
)
})
}).
run
()
}
...
...
@@ -69,7 +69,6 @@ DaoValidator.prototype.hookValidate = function() {
}
// private
var
validateModel
=
function
()
{
Utils
.
_
.
each
(
this
.
model
.
__options
.
validate
,
function
(
_validator
,
validatorType
)
{
var
validator
=
prepareValidationOfAttribute
.
call
(
this
,
undefined
,
_validator
,
validatorType
,
{
omitValue
:
true
})
...
...
@@ -78,11 +77,11 @@ var validateModel = function() {
var
next
=
function
(
err
)
{
if
(
err
)
{
var
error
=
{};
error
[
DaoValidator
.
RAW_KEY_NAME
]
=
err
;
var
error
=
{};
error
[
DaoValidator
.
RAW_KEY_NAME
]
=
err
var
msg
=
((
err
instanceof
Error
)
?
err
.
message
:
err
)
error
[
validatorType
]
=
[
msg
]
var
msg
=
((
err
instanceof
Error
)
?
err
.
message
:
err
)
error
[
validatorType
]
=
[
msg
]
emitter
.
emit
(
'error'
,
error
)
}
else
{
emitter
.
emit
(
'success'
)
...
...
@@ -164,7 +163,7 @@ var prepareValidationOfAttribute = function(value, details, validatorType, optio
try
{
details
.
apply
(
this
.
model
,
callArgs
)
}
catch
(
ex
)
{
return
next
(
ex
)
return
next
(
ex
)
}
if
(
!
isAsync
)
{
...
...
test/dao.validations.test.js
View file @
6d79a93
...
...
@@ -8,7 +8,7 @@ var chai = require('chai')
chai
.
Assertion
.
includeStack
=
true
describe
(
Support
.
getTestDialectTeaser
(
"DaoValidator"
),
function
()
{
describe
.
only
(
'validations'
,
function
()
{
describe
(
'validations'
,
function
()
{
var
checks
=
{
is
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
...
...
@@ -476,7 +476,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
})
})
it
(
'correctly validates using custom validation methods'
,
function
(
done
)
{
it
.
only
(
'correctly validates using custom validation methods'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
{
type
:
Sequelize
.
STRING
,
...
...
@@ -495,6 +495,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
var
failingUser
=
User
.
build
({
name
:
"3"
})
failingUser
.
validate
().
success
(
function
(
errors
)
{
console
.
log
(
'ERR:\n'
,
errors
,
'\n\n'
,
errors
.
name
,
'\n\n'
);
expect
(
errors
).
to
.
deep
.
equal
({
name
:
[
"name should equal '2'"
]
})
var
successfulUser
=
User
.
build
({
name
:
"2"
})
...
...
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