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 4a0a869b
authored
Mar 28, 2016
by
Sushant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(tests) #3534, values modified in validate hooks are saved
1 parent
6486f3c3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
1 deletions
changelog.md
test/integration/hooks/validate.test.js
changelog.md
View file @
4a0a869
# Next
# Future
-
[
FIXED
]
Confirmed that values modified in validation hooks are preserved
[
#3534
](
https://github.com/sequelize/sequelize/issues/3534
)
-
[
FIXED
]
Support lower case type names in SQLite
[
#5482
](
https://github.com/sequelize/sequelize/issues/5482
)
-
[
FIXED
]
Support lower case type names in SQLite
[
#5482
](
https://github.com/sequelize/sequelize/issues/5482
)
# 3.20.0
# 3.20.0
...
...
test/integration/hooks/validate.test.js
View file @
4a0a869
...
@@ -41,6 +41,74 @@ describe(Support.getTestDialectTeaser('Hooks'), function() {
...
@@ -41,6 +41,74 @@ describe(Support.getTestDialectTeaser('Hooks'), function() {
});
});
});
});
describe
(
'#3534, hooks modifications'
,
function
()
{
it
(
'fields modified in hooks are saved'
,
function
()
{
var
self
=
this
;
this
.
User
.
afterValidate
(
function
(
user
,
options
)
{
//if username is defined and has more than 5 char
user
.
username
=
user
.
username
?
(
user
.
username
.
length
<
5
?
null
:
user
.
username
)
:
null
;
user
.
username
=
user
.
username
||
'Samorost 3'
;
});
this
.
User
.
beforeValidate
(
function
(
user
,
options
)
{
user
.
mood
=
user
.
mood
||
'neutral'
;
});
return
this
.
User
.
create
({
username
:
'T'
,
mood
:
'neutral'
}).
then
(
function
(
user
)
{
expect
(
user
.
mood
).
to
.
equal
(
'neutral'
);
expect
(
user
.
username
).
to
.
equal
(
'Samorost 3'
);
//change attributes
user
.
mood
=
'sad'
;
user
.
username
=
'Samorost Good One'
;
return
user
.
save
();
}).
then
(
function
(
uSaved
)
{
expect
(
uSaved
.
mood
).
to
.
equal
(
'sad'
);
expect
(
uSaved
.
username
).
to
.
equal
(
'Samorost Good One'
);
//change attributes, expect to be replaced by hooks
uSaved
.
username
=
'One'
;
return
uSaved
.
save
();
}).
then
(
function
(
uSaved
)
{
//attributes were replaced by hooks ?
expect
(
uSaved
.
mood
).
to
.
equal
(
'sad'
);
expect
(
uSaved
.
username
).
to
.
equal
(
'Samorost 3'
);
return
self
.
User
.
findById
(
uSaved
.
id
);
}).
then
(
function
(
uFetched
)
{
expect
(
uFetched
.
mood
).
to
.
equal
(
'sad'
);
expect
(
uFetched
.
username
).
to
.
equal
(
'Samorost 3'
);
uFetched
.
mood
=
null
;
uFetched
.
username
=
'New Game is Needed'
;
return
uFetched
.
save
();
}).
then
(
function
(
uFetchedSaved
)
{
expect
(
uFetchedSaved
.
mood
).
to
.
equal
(
'neutral'
);
expect
(
uFetchedSaved
.
username
).
to
.
equal
(
'New Game is Needed'
);
return
self
.
User
.
findById
(
uFetchedSaved
.
id
);
}).
then
(
function
(
uFetched
)
{
expect
(
uFetched
.
mood
).
to
.
equal
(
'neutral'
);
expect
(
uFetched
.
username
).
to
.
equal
(
'New Game is Needed'
);
//expect to be replaced by hooks
uFetched
.
username
=
'New'
;
uFetched
.
mood
=
'happy'
;
return
uFetched
.
save
();
}).
then
(
function
(
uFetchedSaved
)
{
expect
(
uFetchedSaved
.
mood
).
to
.
equal
(
'happy'
);
expect
(
uFetchedSaved
.
username
).
to
.
equal
(
'Samorost 3'
);
});
});
});
describe
(
'on error'
,
function
()
{
describe
(
'on error'
,
function
()
{
it
(
'should emit an error from after hook'
,
function
()
{
it
(
'should emit an error from after hook'
,
function
()
{
this
.
User
.
afterValidate
(
function
(
user
,
options
)
{
this
.
User
.
afterValidate
(
function
(
user
,
options
)
{
...
...
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