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 4d1d686c
authored
Jan 03, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test virtual getters aswell
1 parent
ef41cb1a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
5 deletions
lib/dao.js
test/dao/values.test.js
lib/dao.js
View file @
4d1d686
...
@@ -104,11 +104,17 @@ module.exports = (function() {
...
@@ -104,11 +104,17 @@ module.exports = (function() {
var
values
=
{}
var
values
=
{}
,
key
,
key
for
(
key
in
this
.
dataValue
s
)
{
for
(
key
in
this
.
_customGetter
s
)
{
if
(
this
.
dataValue
s
.
hasOwnProperty
(
key
))
{
if
(
this
.
_customGetter
s
.
hasOwnProperty
(
key
))
{
values
[
key
]
=
this
.
get
(
key
)
values
[
key
]
=
this
.
get
(
key
)
}
}
}
}
for
(
key
in
this
.
dataValues
)
{
if
(
!
values
.
hasOwnProperty
(
key
)
&&
this
.
dataValues
.
hasOwnProperty
(
key
))
{
values
[
key
]
=
this
.
dataValues
[
key
]
}
}
return
values
return
values
}
}
return
this
.
dataValues
return
this
.
dataValues
...
...
test/dao/values.test.js
View file @
4d1d686
...
@@ -137,10 +137,10 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -137,10 +137,10 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
})
describe
(
'get'
,
function
()
{
describe
(
'get'
,
function
()
{
it
(
'should use custom getters in get(key)'
,
function
()
{
it
(
'should use custom
attribute
getters in get(key)'
,
function
()
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
price
:
{
price
:
{
type
:
Sequelize
.
STRING
,
type
:
Sequelize
.
FLOAT
,
get
:
function
()
{
get
:
function
()
{
return
this
.
dataValues
[
'price'
]
*
100
return
this
.
dataValues
[
'price'
]
*
100
}
}
...
@@ -153,6 +153,25 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -153,6 +153,25 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
expect
(
product
.
get
(
'price'
)).
to
.
equal
(
1000
)
expect
(
product
.
get
(
'price'
)).
to
.
equal
(
1000
)
})
})
it
(
'should custom virtual getters in get(key)'
,
function
()
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
priceInCents
:
{
type
:
Sequelize
.
FLOAT
}
},
{
getterMethods
:
{
price
:
function
()
{
return
this
.
dataValues
[
'priceInCents'
]
/
100
}
}
})
var
product
=
Product
.
build
({
priceInCents
:
1000
})
expect
(
product
.
get
(
'price'
)).
to
.
equal
(
10
)
})
it
(
'should use custom getters in toJSON'
,
function
()
{
it
(
'should use custom getters in toJSON'
,
function
()
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
var
Product
=
this
.
sequelize
.
define
(
'Product'
,
{
price
:
{
price
:
{
...
@@ -161,12 +180,18 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
...
@@ -161,12 +180,18 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
return
this
.
dataValues
[
'price'
]
*
100
return
this
.
dataValues
[
'price'
]
*
100
}
}
}
}
},
{
getterMethods
:
{
withTaxes
:
function
()
{
return
this
.
get
(
'price'
)
*
1.25
}
}
})
})
var
product
=
Product
.
build
({
var
product
=
Product
.
build
({
price
:
10
price
:
10
})
})
expect
(
product
.
toJSON
()).
to
.
deep
.
equal
({
price
:
1000
,
id
:
null
})
expect
(
product
.
toJSON
()).
to
.
deep
.
equal
({
withTaxes
:
1250
,
price
:
1000
,
id
:
null
})
})
})
})
})
...
...
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