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 300c531f
authored
Aug 23, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge
1 parent
6c68eb11
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
16 deletions
lib/dao-factory.js
test/dao.validations.test.js
lib/dao-factory.js
View file @
300c531
...
@@ -169,7 +169,7 @@ module.exports = (function() {
...
@@ -169,7 +169,7 @@ module.exports = (function() {
this
.
DAO
.
prototype
.
__factory
=
this
this
.
DAO
.
prototype
.
__factory
=
this
this
.
DAO
.
prototype
.
hasDefaultValues
=
!
Utils
.
_
.
isEmpty
(
this
.
DAO
.
prototype
.
defaultValues
)
this
.
DAO
.
prototype
.
hasDefaultValues
=
!
Utils
.
_
.
isEmpty
(
this
.
DAO
.
prototype
.
defaultValues
)
return
this
return
this
}
}
...
@@ -334,7 +334,7 @@ module.exports = (function() {
...
@@ -334,7 +334,7 @@ module.exports = (function() {
options
=
{
where
:
parseInt
(
Number
(
options
)
||
0
,
0
)}
options
=
{
where
:
parseInt
(
Number
(
options
)
||
0
,
0
)}
}
}
}
}
options
.
limit
=
1
options
.
limit
=
1
return
this
.
QueryInterface
.
select
(
this
,
this
.
getTableName
(),
options
,
Utils
.
_
.
defaults
({
return
this
.
QueryInterface
.
select
(
this
,
this
.
getTableName
(),
options
,
Utils
.
_
.
defaults
({
...
@@ -578,16 +578,25 @@ module.exports = (function() {
...
@@ -578,16 +578,25 @@ module.exports = (function() {
attrValueHash
[
attr
]
=
Utils
.
now
()
attrValueHash
[
attr
]
=
Utils
.
now
()
}
}
if
(
options
.
validate
===
true
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
validate
=
this
.
build
(
attrValueHash
).
validate
()
if
(
options
.
validate
===
true
)
{
if
(
validate
!==
null
&&
Object
.
keys
(
validate
).
length
>
0
)
{
this
.
build
(
attrValueHash
).
validate
().
success
(
function
(
errors
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
if
(
!!
errors
)
{
emitter
.
emit
(
'error'
,
validate
)
emitter
.
emit
(
'error'
,
errors
)
}).
run
()
}
else
{
this
.
QueryInterface
.
bulkUpdate
(
this
.
tableName
,
attrValueHash
,
where
,
options
)
.
proxy
(
emitter
)
}
}.
bind
(
this
))
}
else
{
this
.
QueryInterface
.
bulkUpdate
(
this
.
tableName
,
attrValueHash
,
where
,
options
)
.
proxy
(
emitter
)
}
}
}
}.
bind
(
this
)).
run
()
return
this
.
QueryInterface
.
bulkUpdate
(
this
.
tableName
,
attrValueHash
,
where
,
options
)
}
}
DAOFactory
.
prototype
.
describe
=
function
(
schema
)
{
DAOFactory
.
prototype
.
describe
=
function
(
schema
)
{
...
...
test/dao.validations.test.js
View file @
300c531
...
@@ -275,7 +275,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -275,7 +275,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
model
.
updateAttributes
({
name
:
''
}).
error
(
function
(
err
)
{
model
.
updateAttributes
({
name
:
''
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
deep
.
equal
({
name
:
[
'String is empty
: name'
,
'String is empty: name
'
]
})
expect
(
err
).
to
.
deep
.
equal
({
name
:
[
'String is empty'
]
})
done
()
done
()
})
})
})
})
...
@@ -296,7 +296,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -296,7 +296,7 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
sync
({
force
:
true
}).
success
(
function
()
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
Model
.
create
({
name
:
'World'
}).
success
(
function
(
model
)
{
Model
.
update
({
name
:
''
},
{
id
:
1
}).
error
(
function
(
err
)
{
Model
.
update
({
name
:
''
},
{
id
:
1
}).
error
(
function
(
err
)
{
expect
(
err
).
to
.
deep
.
equal
({
name
:
[
'String is empty
: name'
,
'String is empty: name
'
]
})
expect
(
err
).
to
.
deep
.
equal
({
name
:
[
'String is empty'
]
})
done
()
done
()
})
})
})
})
...
@@ -427,10 +427,11 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
...
@@ -427,10 +427,11 @@ describe(Support.getTestDialectTeaser("DaoValidator"), function() {
it
(
'should emit an error when we try to enter in a string for an auto increment key through .build().validate()'
,
function
(
done
)
{
it
(
'should emit an error when we try to enter in a string for an auto increment key through .build().validate()'
,
function
(
done
)
{
var
user
=
this
.
User
.
build
({
id
:
'helloworld'
})
var
user
=
this
.
User
.
build
({
id
:
'helloworld'
})
,
errors
=
user
.
validate
()
expect
(
errors
).
to
.
deep
.
equal
({
id
:
[
'ID must be an integer!'
]
})
user
.
validate
().
success
(
function
(
errors
)
{
done
()
expect
(
errors
).
to
.
deep
.
equal
({
id
:
[
'ID must be an integer!'
]
})
done
()
})
})
})
it
(
'should emit an error when we try to .save()'
,
function
(
done
)
{
it
(
'should emit an error when we try to .save()'
,
function
(
done
)
{
...
...
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