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 88622127
authored
Oct 14, 2017
by
Sushant
Committed by
GitHub
Oct 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(datatypes): DATE/DATEONLY marked as changed when changed from null to null (#8483)
1 parent
669f09fd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
7 deletions
lib/data-types.js
test/unit/instance/changed.test.js
lib/data-types.js
View file @
8862212
...
...
@@ -355,6 +355,11 @@ DATE.prototype._isChanged = function _isChanged(value, originalValue) {
return
false
;
}
// not changed when set to same empty value
if
(
!
originalValue
&&
!
value
&&
originalValue
===
value
)
{
return
false
;
}
return
true
;
};
...
...
@@ -406,6 +411,11 @@ DATEONLY.prototype._isChanged = function _isChanged(value, originalValue) {
return
false
;
}
// not changed when set to same empty value
if
(
!
originalValue
&&
!
value
&&
originalValue
===
value
)
{
return
false
;
}
return
true
;
};
...
...
test/unit/instance/changed.test.js
View file @
8862212
...
...
@@ -11,7 +11,8 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
beforeEach
(
function
()
{
this
.
User
=
current
.
define
(
'User'
,
{
name
:
DataTypes
.
STRING
,
birthdate
:
DataTypes
.
DATE
,
birthday
:
DataTypes
.
DATE
,
yoj
:
DataTypes
.
DATEONLY
,
meta
:
DataTypes
.
JSON
});
});
...
...
@@ -49,16 +50,16 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
it
(
'should return true for multiple changed values'
,
function
()
{
const
user
=
this
.
User
.
build
({
name
:
'a'
,
birthda
te
:
new
Date
(
new
Date
()
-
10
)
birthda
y
:
new
Date
(
new
Date
()
-
10
)
},
{
isNewRecord
:
false
,
raw
:
true
});
user
.
set
(
'name'
,
'b'
);
user
.
set
(
'birthda
te
'
,
new
Date
());
user
.
set
(
'birthda
y
'
,
new
Date
());
expect
(
user
.
changed
(
'name'
)).
to
.
equal
(
true
);
expect
(
user
.
changed
(
'birthda
te
'
)).
to
.
equal
(
true
);
expect
(
user
.
changed
(
'birthda
y
'
)).
to
.
equal
(
true
);
});
it
(
'should return false for two instances with same value'
,
function
()
{
...
...
@@ -67,14 +68,14 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
const
secondDate
=
new
Date
(
milliseconds
);
const
user
=
this
.
User
.
build
({
birthda
te
:
firstDate
birthda
y
:
firstDate
},
{
isNewRecord
:
false
,
raw
:
true
});
user
.
set
(
'birthda
te
'
,
secondDate
);
expect
(
user
.
changed
(
'birthda
te
'
)).
to
.
equal
(
false
);
user
.
set
(
'birthda
y
'
,
secondDate
);
expect
(
user
.
changed
(
'birthda
y
'
)).
to
.
equal
(
false
);
});
it
(
'should return true for changed JSON with same object'
,
function
()
{
...
...
@@ -149,5 +150,25 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
user
.
set
(
'meta.address'
,
{
street
:
'Main street'
,
number
:
'40'
}
);
expect
(
user
.
changed
(
'meta'
)).
to
.
equal
(
false
);
});
it
(
'should return false when changed from null to null'
,
function
()
{
const
attributes
=
{};
for
(
const
attr
in
this
.
User
.
rawAttributes
)
{
attributes
[
attr
]
=
null
;
}
const
user
=
this
.
User
.
build
(
attributes
,
{
isNewRecord
:
false
,
raw
:
true
});
for
(
const
attr
in
this
.
User
.
rawAttributes
)
{
user
.
set
(
attr
,
null
);
}
for
(
const
attr
in
this
.
User
.
rawAttributes
)
{
expect
(
user
.
changed
(
attr
),
`
${
attr
}
is not changed`
).
to
.
equal
(
false
);
}
});
});
});
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