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 8727c817
authored
Dec 03, 2015
by
Sorin Neacsu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Utils.toDefaultValue - clone value for objects and strings to prevent mutating it
1 parent
8d752082
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
2 deletions
lib/utils.js
test/unit/instance/set.test.js
lib/utils.js
View file @
8727c81
...
@@ -232,6 +232,8 @@ var Utils = module.exports = {
...
@@ -232,6 +232,8 @@ var Utils = module.exports = {
return
uuid
.
v4
();
return
uuid
.
v4
();
}
else
if
(
value
instanceof
DataTypes
.
NOW
)
{
}
else
if
(
value
instanceof
DataTypes
.
NOW
)
{
return
Utils
.
now
();
return
Utils
.
now
();
}
else
if
(
_
.
isPlainObject
(
value
)
||
_
.
isArray
(
value
))
{
return
_
.
clone
(
value
);
}
else
{
}
else
{
return
value
;
return
value
;
}
}
...
...
test/unit/instance/set.test.js
View file @
8727c81
...
@@ -28,6 +28,21 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
...
@@ -28,6 +28,21 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
expect
(
user
.
dataValues
[
'meta.location'
]).
not
.
to
.
be
.
ok
;
expect
(
user
.
dataValues
[
'meta.location'
]).
not
.
to
.
be
.
ok
;
expect
(
user
.
get
(
'meta'
).
location
).
to
.
equal
(
'Copenhagen'
);
expect
(
user
.
get
(
'meta'
).
location
).
to
.
equal
(
'Copenhagen'
);
expect
(
user
.
get
(
'meta'
)
===
meta
).
to
.
equal
(
true
);
expect
(
user
.
get
(
'meta'
)
===
meta
).
to
.
equal
(
true
);
expect
(
user
.
get
(
'meta'
)
===
meta
).
to
.
equal
(
true
);
});
it
(
'doesnt mutate the JSONB defaultValue'
,
function
()
{
var
User
=
current
.
define
(
'User'
,
{
meta
:
{
type
:
DataTypes
.
JSONB
,
allowNull
:
false
,
defaultValue
:
{}
}
});
var
user1
=
User
.
build
({});
user1
.
set
(
'meta.location'
,
'Stockhollm'
);
var
user2
=
User
.
build
({});
expect
(
user2
.
get
(
'meta'
)).
to
.
deep
.
equal
({});
});
});
});
});
});
});
\ No newline at end of file
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