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 c739f1a6
authored
Jan 28, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
added tests for new timestamp feature
2 parents
a26450bb
31a05e22
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
7 deletions
lib/dao-factory.js
lib/dao.js
spec/dao.spec.js
lib/dao-factory.js
View file @
c739f1a
...
...
@@ -255,12 +255,12 @@ module.exports = (function() {
}
DAOFactory
.
prototype
.
build
=
function
(
values
,
options
)
{
options
=
options
||
{}
options
=
options
||
{
isNewRecord
:
true
}
var
self
=
this
,
instance
=
new
this
.
DAO
(
values
,
this
.
options
)
,
instance
=
new
this
.
DAO
(
values
,
this
.
options
,
options
.
isNewRecord
)
instance
.
isNewRecord
=
options
.
hasOwnProperty
(
'isNewRecord'
)
?
options
.
isNewRecord
:
true
instance
.
isNewRecord
=
options
.
isNewRecord
return
instance
}
...
...
lib/dao.js
View file @
c739f1a
...
...
@@ -4,13 +4,13 @@ var Utils = require("./utils")
,
DataTypes
=
require
(
"./data-types"
)
module
.
exports
=
(
function
()
{
var
DAO
=
function
(
values
,
options
)
{
var
DAO
=
function
(
values
,
options
,
isNewRecord
)
{
var
self
=
this
;
this
.
__options
=
options
;
this
.
hasPrimaryKeys
=
options
.
hasPrimaryKeys
;
this
.
selectedValues
=
values
;
initAttributes
.
call
(
this
,
values
)
initAttributes
.
call
(
this
,
values
,
isNewRecord
)
if
(
this
.
hasDefaultValues
)
{
Utils
.
_
.
each
(
this
.
defaultValues
,
function
(
value
,
name
)
{
...
...
@@ -271,7 +271,7 @@ module.exports = (function() {
// private
var
initAttributes
=
function
(
values
)
{
var
initAttributes
=
function
(
values
,
isNewRecord
)
{
// add all passed values to the dao and store the attribute names in this.attributes
for
(
var
key
in
values
)
{
if
(
values
.
hasOwnProperty
(
key
))
{
...
...
@@ -283,7 +283,7 @@ module.exports = (function() {
// a newly created dao has no id
var
defaults
=
this
.
hasPrimaryKeys
?
{}
:
{
id
:
null
}
if
(
this
.
__options
.
timestamps
)
{
if
(
this
.
__options
.
timestamps
&&
isNewRecord
)
{
defaults
[
this
.
__options
.
underscored
?
'created_at'
:
'createdAt'
]
=
new
Date
()
defaults
[
this
.
__options
.
underscored
?
'updated_at'
:
'updatedAt'
]
=
new
Date
()
...
...
spec/dao.spec.js
View file @
c739f1a
...
...
@@ -148,5 +148,25 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
})
})
})
it
(
"returns the timestamps if no attributes have been specified"
,
function
(
done
)
{
this
.
User
.
create
({
username
:
'fnord'
}).
success
(
function
()
{
this
.
User
.
findAll
().
success
(
function
(
users
)
{
expect
(
users
[
0
].
createdAt
).
toBeDefined
()
done
()
}.
bind
(
this
))
}.
bind
(
this
))
})
it
(
"does not return the timestamps if the username attribute has been specified"
,
function
(
done
)
{
this
.
User
.
create
({
username
:
'fnord'
}).
success
(
function
()
{
this
.
User
.
findAll
({
attributes
:
[
'username'
]
}).
success
(
function
(
users
)
{
expect
(
users
[
0
].
createdAt
).
not
.
toBeDefined
()
expect
(
users
[
0
].
username
).
toBeDefined
()
done
()
}.
bind
(
this
))
}.
bind
(
this
))
})
})
})
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