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 5e68ef9d
authored
Jun 08, 2013
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #665
1 parent
eaefe44c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
8 deletions
lib/dao.js
spec/dao-factory.spec.js
spec/dao.spec.js
spec/dao.validations.spec.js
lib/dao.js
View file @
5e68ef9
...
...
@@ -365,20 +365,22 @@ module.exports = (function() {
}
}
if
(
this
.
__options
.
timestamps
&&
isNewRecord
)
{
defaults
[
this
.
__options
.
underscored
?
'created_at'
:
'createdAt'
]
=
Utils
.
now
()
defaults
[
this
.
__options
.
underscored
?
'updated_at'
:
'updatedAt'
]
=
Utils
.
now
()
if
(
this
.
__options
.
paranoid
)
{
defaults
[
this
.
__options
.
underscored
?
'deleted_at'
:
'deletedAt'
]
=
null
}
if
(
isNewRecord
)
{
if
(
this
.
hasDefaultValues
)
{
Utils
.
_
.
each
(
this
.
defaultValues
,
function
(
valueFn
,
key
)
{
if
(
!
defaults
.
hasOwnProperty
(
key
))
defaults
[
key
]
=
valueFn
()
})
}
if
(
this
.
__options
.
timestamps
)
{
defaults
[
this
.
__options
.
underscored
?
'created_at'
:
'createdAt'
]
=
Utils
.
now
()
defaults
[
this
.
__options
.
underscored
?
'updated_at'
:
'updatedAt'
]
=
Utils
.
now
()
if
(
this
.
__options
.
paranoid
)
{
defaults
[
this
.
__options
.
underscored
?
'deleted_at'
:
'deletedAt'
]
=
null
}
}
}
if
(
Utils
.
_
.
size
(
defaults
))
{
...
...
spec/dao-factory.spec.js
View file @
5e68ef9
...
...
@@ -7,6 +7,7 @@ if(typeof require === 'function') {
}
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
1000
describe
(
Helpers
.
getTestDialectTeaser
(
"DAOFactory"
),
function
()
{
before
(
function
(
done
)
{
...
...
@@ -124,6 +125,21 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
expect
(
Task
.
build
().
flag
).
toEqual
(
false
)
})
it
(
"fills the objects with default values"
,
function
()
{
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
{
type
:
Sequelize
.
STRING
,
defaultValue
:
'a task!'
},
foo
:
{
type
:
Sequelize
.
INTEGER
,
defaultValue
:
2
},
bar
:
{
type
:
Sequelize
.
DATE
},
foobar
:
{
type
:
Sequelize
.
TEXT
,
defaultValue
:
'asd'
},
flag
:
{
type
:
Sequelize
.
BOOLEAN
,
defaultValue
:
false
}
},
{
timestamps
:
false
})
expect
(
Task
.
build
().
title
).
toEqual
(
'a task!'
)
expect
(
Task
.
build
().
foo
).
toEqual
(
2
)
expect
(
Task
.
build
().
bar
).
toEqual
(
undefined
)
expect
(
Task
.
build
().
foobar
).
toEqual
(
'asd'
)
expect
(
Task
.
build
().
flag
).
toEqual
(
false
)
})
it
(
"stores the the passed values in a special variable"
,
function
()
{
var
user
=
this
.
User
.
build
({
username
:
'John Wayne'
})
expect
(
user
.
selectedValues
).
toEqual
({
username
:
'John Wayne'
})
...
...
spec/dao.spec.js
View file @
5e68ef9
...
...
@@ -6,6 +6,7 @@ if (typeof require === 'function') {
}
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
1000
describe
(
Helpers
.
getTestDialectTeaser
(
"DAO"
),
function
()
{
before
(
function
(
done
)
{
...
...
spec/dao.validations.spec.js
View file @
5e68ef9
...
...
@@ -6,6 +6,7 @@ if(typeof require === 'function') {
}
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
1000
describe
(
Helpers
.
getTestDialectTeaser
(
"DaoValidator"
),
function
()
{
describe
(
'validations'
,
function
()
{
...
...
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