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 f8d0eabf
authored
Nov 14, 2016
by
Robert Scheinpflug
Committed by
Sushant
Nov 14, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix instance.set '1970-01-01' to null field (#6853)
1 parent
1fcd126b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
12 deletions
lib/model.js
test/unit/instance/set.test.js
lib/model.js
View file @
f8d0eab
...
@@ -3101,11 +3101,13 @@ class Model {
...
@@ -3101,11 +3101,13 @@ class Model {
if
(
!
(
value
instanceof
Date
))
{
if
(
!
(
value
instanceof
Date
))
{
value
=
new
Date
(
value
);
value
=
new
Date
(
value
);
}
}
if
(
!
(
originalValue
instanceof
Date
))
{
if
(
originalValue
)
{
originalValue
=
new
Date
(
originalValue
);
if
(
!
(
originalValue
instanceof
Date
))
{
}
originalValue
=
new
Date
(
originalValue
);
if
(
originalValue
&&
value
.
getTime
()
===
originalValue
.
getTime
())
{
}
return
this
;
if
(
value
.
getTime
()
===
originalValue
.
getTime
())
{
return
this
;
}
}
}
}
}
}
}
...
...
test/unit/instance/set.test.js
View file @
f8d0eab
'use strict'
;
'use strict'
;
/* jshint -W030 */
/* jshint -W030 */
var
chai
=
require
(
'chai'
)
const
chai
=
require
(
'chai'
)
,
expect
=
chai
.
expect
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/../support'
)
,
Support
=
require
(
__dirname
+
'/../support'
)
,
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
)
,
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
)
...
@@ -10,10 +10,10 @@ var chai = require('chai')
...
@@ -10,10 +10,10 @@ var chai = require('chai')
describe
(
Support
.
getTestDialectTeaser
(
'Instance'
),
function
()
{
describe
(
Support
.
getTestDialectTeaser
(
'Instance'
),
function
()
{
describe
(
'set'
,
function
()
{
describe
(
'set'
,
function
()
{
it
(
'sets nested keys in JSON objects'
,
function
()
{
it
(
'sets nested keys in JSON objects'
,
function
()
{
var
User
=
current
.
define
(
'User'
,
{
const
User
=
current
.
define
(
'User'
,
{
meta
:
DataTypes
.
JSONB
meta
:
DataTypes
.
JSONB
});
});
var
user
=
User
.
build
({
const
user
=
User
.
build
({
meta
:
{
meta
:
{
location
:
'Stockhollm'
location
:
'Stockhollm'
}
}
...
@@ -22,7 +22,7 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
...
@@ -22,7 +22,7 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
raw
:
true
raw
:
true
});
});
var
meta
=
user
.
get
(
'meta'
);
const
meta
=
user
.
get
(
'meta'
);
user
.
set
(
'meta.location'
,
'Copenhagen'
);
user
.
set
(
'meta.location'
,
'Copenhagen'
);
expect
(
user
.
dataValues
[
'meta.location'
]).
not
.
to
.
be
.
ok
;
expect
(
user
.
dataValues
[
'meta.location'
]).
not
.
to
.
be
.
ok
;
...
@@ -32,17 +32,48 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
...
@@ -32,17 +32,48 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
});
});
it
(
'doesnt mutate the JSONB defaultValue'
,
function
()
{
it
(
'doesnt mutate the JSONB defaultValue'
,
function
()
{
var
User
=
current
.
define
(
'User'
,
{
const
User
=
current
.
define
(
'User'
,
{
meta
:
{
meta
:
{
type
:
DataTypes
.
JSONB
,
type
:
DataTypes
.
JSONB
,
allowNull
:
false
,
allowNull
:
false
,
defaultValue
:
{}
defaultValue
:
{}
}
}
});
});
var
user1
=
User
.
build
({});
const
user1
=
User
.
build
({});
user1
.
set
(
'meta.location'
,
'Stockhollm'
);
user1
.
set
(
'meta.location'
,
'Stockhollm'
);
var
user2
=
User
.
build
({});
const
user2
=
User
.
build
({});
expect
(
user2
.
get
(
'meta'
)).
to
.
deep
.
equal
({});
expect
(
user2
.
get
(
'meta'
)).
to
.
deep
.
equal
({});
});
});
it
(
'sets the date "1970-01-01" to previously null field'
,
function
()
{
const
User
=
current
.
define
(
'User'
,
{
date
:
{
type
:
DataTypes
.
DATE
,
allowNull
:
true
}
});
const
user1
=
User
.
build
({
date
:
null
});
user1
.
set
(
'date'
,
'1970-01-01'
);
expect
(
user1
.
get
(
'date'
)).
to
.
be
.
ok
;
expect
(
user1
.
get
(
'date'
).
getTime
()).
to
.
equal
(
new
Date
(
'1970-01-01'
).
getTime
());
});
it
(
'overwrites non-date originalValue with date'
,
function
()
{
const
User
=
current
.
define
(
'User'
,
{
date
:
DataTypes
.
DATE
});
const
user
=
User
.
build
({
date
:
' '
},
{
isNewRecord
:
false
,
raw
:
true
});
user
.
set
(
'date'
,
new
Date
());
expect
(
user
.
get
(
'date'
)).
to
.
be
.
an
.
instanceof
(
Date
);
expect
(
user
.
get
(
'date'
)).
not
.
to
.
be
.
NaN
;
});
});
});
});
});
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