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 412385f1
authored
Mar 07, 2014
by
Thanasis Polychronakis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restore error being an instance of Seq Validation error
1 parent
0330637f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
16 deletions
lib/dao-validator.js
test/dao.validations.test.js
lib/dao-validator.js
View file @
412385f
...
...
@@ -106,10 +106,10 @@ var DaoValidator = module.exports = function(modelInstance, optOptions) {
/**
* All errors will be stored here from the validations.
*
* @type {
Object
} Will contain keys that correspond to attributes which will
* @type {
Sequelize.error
} Will contain keys that correspond to attributes which will
* be Arrays of Errors.
*/
this
.
errors
=
{}
this
.
errors
=
new
sequelizeError
.
ValidationError
(
'Validation error'
)
/** @type {boolean} Indicates if validations are in progress */
this
.
inProgress
=
false
;
...
...
@@ -128,7 +128,7 @@ DaoValidator.prototype.validate = function() {
throw
new
Error
(
'Validations already in progress.'
);
}
this
.
inProgress
=
true
;
this
.
errors
=
{}
this
.
errors
=
new
sequelizeError
.
ValidationError
(
'Validation error'
)
var
self
=
this
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
...
...
test/dao.validations.test.js
View file @
412385f
...
...
@@ -201,7 +201,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
failingUser
.
validate
().
done
(
function
(
err
,
_errors
)
{
expect
(
_errors
).
to
.
not
.
be
.
null
expect
(
_errors
).
to
.
be
.
an
(
'Object'
);
expect
(
_errors
).
to
.
be
.
an
.
instanceOf
(
Error
)
expect
(
_errors
.
name
).
to
.
deep
.
eql
([
message
])
done
()
})
...
...
@@ -301,7 +301,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
model
.
updateAttributes
({
name
:
''
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
).
to
.
be
.
an
.
instanceOf
(
Error
)
expect
(
err
.
name
).
to
.
deep
.
equal
([
'Validation notEmpty failed'
]);
done
()
})
...
...
@@ -323,7 +323,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
Model
.
update
({
name
:
''
},
{
id
:
1
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
).
to
.
be
.
an
.
instanceOf
(
Error
)
expect
(
err
.
name
).
to
.
deep
.
equal
([
'Validation notEmpty failed'
])
done
()
})
...
...
@@ -400,7 +400,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
id
:
'helloworld'
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
).
to
.
be
.
an
.
instanceOf
(
Error
)
expect
(
err
.
id
).
to
.
deep
.
equal
([
'Validation isInt failed'
])
done
()
})
...
...
@@ -421,7 +421,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'helloworldhelloworld'
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
).
to
.
be
.
an
.
instanceOf
(
Error
)
expect
(
err
.
username
).
to
.
deep
.
equal
([
'Username must be an integer!'
])
done
()
})
...
...
@@ -448,7 +448,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
it
(
'should emit an error when we try to enter in a string for the id key with validation arguments'
,
function
(
done
)
{
this
.
User
.
create
({
id
:
'helloworld'
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
).
to
.
be
.
an
.
instanceOf
(
Error
)
expect
(
err
.
id
).
to
.
deep
.
equal
([
'ID must be an integer!'
])
done
()
})
...
...
@@ -458,7 +458,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
var
user
=
this
.
User
.
build
({
id
:
'helloworld'
})
user
.
validate
().
success
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
).
to
.
be
.
an
.
instanceOf
(
Error
)
expect
(
err
.
id
).
to
.
deep
.
equal
([
'ID must be an integer!'
])
done
()
})
...
...
@@ -467,7 +467,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
it
(
'should emit an error when we try to .save()'
,
function
(
done
)
{
var
user
=
this
.
User
.
build
({
id
:
'helloworld'
})
user
.
save
().
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
an
(
'Object'
)
expect
(
err
).
to
.
be
.
an
.
instanceOf
(
Error
)
expect
(
err
.
id
).
to
.
deep
.
equal
([
'ID must be an integer!'
])
done
()
})
...
...
@@ -515,7 +515,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
it
(
'produce 3 errors'
,
function
(
done
)
{
this
.
Project
.
create
({}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
be
.
an
(
'Object'
);
expect
(
err
).
to
.
be
.
an
.
instanceOf
(
Error
)
expect
(
Object
.
keys
(
err
)).
to
.
have
.
length
(
3
)
done
()
})
...
...
@@ -542,7 +542,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
var
failingUser
=
User
.
build
({
name
:
"3"
})
failingUser
.
validate
().
success
(
function
(
error
)
{
expect
(
error
).
to
.
be
.
an
(
'Object'
);
expect
(
error
).
to
.
be
.
an
.
instanceOf
(
Error
)
expect
(
error
.
name
[
0
].
message
).
to
.
equal
(
"name should equal '2'"
)
...
...
@@ -573,7 +573,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
.
validate
()
.
success
(
function
(
error
)
{
expect
(
error
).
not
.
to
.
be
.
null
expect
(
error
).
to
.
be
.
an
(
'Object'
);
expect
(
error
).
to
.
be
.
an
.
instanceOf
(
Error
)
expect
(
error
.
age
).
to
.
deep
.
equal
([
"must be positive"
])
User
.
build
({
age
:
null
}).
validate
().
success
(
function
()
{
...
...
@@ -611,7 +611,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
.
validate
()
.
success
(
function
(
error
)
{
expect
(
error
).
not
.
to
.
be
.
null
expect
(
error
).
to
.
be
.
an
(
'Object'
)
expect
(
error
).
to
.
be
.
an
.
instanceOf
(
Error
)
expect
(
error
.
xnor
[
0
].
message
).
to
.
equal
(
'xnor failed'
);
Foo
...
...
@@ -649,7 +649,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
.
validate
()
.
success
(
function
(
error
)
{
expect
(
error
).
not
.
to
.
be
.
null
expect
(
error
).
to
.
be
.
an
(
'Object'
)
expect
(
error
).
to
.
be
.
an
.
instanceOf
(
Error
)
expect
(
error
.
xnor
[
0
].
message
).
to
.
equal
(
'xnor failed'
)
Foo
...
...
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