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 e97fb601
authored
Mar 06, 2014
by
tomchentw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(HSTORE): add some related tests
1 parent
f21958f9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
13 deletions
test/postgres/dao.test.js
test/postgres/dao.test.js
View file @
e97fb60
...
@@ -14,6 +14,7 @@ if (dialect.match(/^postgres/)) {
...
@@ -14,6 +14,7 @@ if (dialect.match(/^postgres/)) {
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
,
username
:
DataTypes
.
STRING
,
email
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
TEXT
)},
email
:
{
type
:
DataTypes
.
ARRAY
(
DataTypes
.
TEXT
)},
settings
:
DataTypes
.
HSTORE
,
document
:
{
type
:
DataTypes
.
HSTORE
,
defaultValue
:
'"default"=>"value"'
}
document
:
{
type
:
DataTypes
.
HSTORE
,
defaultValue
:
'"default"=>"value"'
}
})
})
this
.
User
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
sync
({
force
:
true
}).
success
(
function
()
{
...
@@ -48,10 +49,25 @@ if (dialect.match(/^postgres/)) {
...
@@ -48,10 +49,25 @@ if (dialect.match(/^postgres/)) {
})
})
})
})
it
(
'describeTable should tell me that a column is hstore and not USER-DEFINED'
,
function
(
done
)
{
describe
(
'hstore'
,
function
()
{
this
.
sequelize
.
queryInterface
.
describeTable
(
'Users'
).
success
(
function
(
table
)
{
it
(
'should tell me that a column is hstore and not USER-DEFINED'
,
function
(
done
)
{
expect
(
table
.
document
.
type
).
to
.
equal
(
'HSTORE'
)
this
.
sequelize
.
queryInterface
.
describeTable
(
'Users'
).
success
(
function
(
table
)
{
done
()
expect
(
table
.
settings
.
type
).
to
.
equal
(
'HSTORE'
)
expect
(
table
.
document
.
type
).
to
.
equal
(
'HSTORE'
)
done
()
})
})
it
(
'should stringify hstore with insert'
,
function
(
done
)
{
this
.
User
.
create
({
username
:
'bob'
,
email
:
[
'myemail@email.com'
],
settings
:
{
mailing
:
false
,
push
:
'facebook'
,
frequency
:
3
}
}).
on
(
'sql'
,
function
(
sql
)
{
var
expected
=
'INSERT INTO "Users" ("id","username","email","settings","document","createdAt","updatedAt") VALUES (DEFAULT,\'bob\',ARRAY[\'myemail@email.com\']::TEXT[],\'"mailing"=>false,"push"=>"facebook","frequency"=>3\',\'"default"=>"value"\''
expect
(
sql
.
indexOf
(
expected
)).
to
.
equal
(
0
)
done
()
})
})
})
})
})
...
@@ -242,19 +258,17 @@ if (dialect.match(/^postgres/)) {
...
@@ -242,19 +258,17 @@ if (dialect.match(/^postgres/)) {
var
self
=
this
var
self
=
this
this
.
User
this
.
User
.
create
({
username
:
'user'
,
email
:
[
'foo@bar.com'
],
document
:
{
created
:
{
test
:
'"value"'
}}})
.
create
({
username
:
'user'
,
email
:
[
'foo@bar.com'
],
settings
:
{
created
:
{
test
:
'"value"'
}}})
.
success
(
function
(
newUser
)
{
.
success
(
function
(
newUser
)
{
expect
(
newUser
.
document
).
to
.
deep
.
equal
({
created
:
{
test
:
'"value"'
}})
// Check to see if the default value for an hstore field works
expect
(
newUser
.
document
).
to
.
deep
.
equal
({
default
:
'value'
})
expect
(
newUser
.
settings
).
to
.
deep
.
equal
({
created
:
{
test
:
'"value"'
}})
// Check to see if updating an hstore field works
// Check to see if updating an hstore field works
newUser
.
updateAttributes
({
document
:
{
should
:
'update'
,
to
:
'this'
,
first
:
'place'
}}).
success
(
function
(
oldUser
){
newUser
.
updateAttributes
({
settings
:
{
should
:
'update'
,
to
:
'this'
,
first
:
'place'
}}).
success
(
function
(
oldUser
){
// Postgres always returns keys in alphabetical order (ascending)
// Postgres always returns keys in alphabetical order (ascending)
expect
(
oldUser
.
document
).
to
.
deep
.
equal
({
first
:
'place'
,
should
:
'update'
,
to
:
'this'
})
expect
(
oldUser
.
settings
).
to
.
deep
.
equal
({
first
:
'place'
,
should
:
'update'
,
to
:
'this'
})
// Check to see if the default value for an hstore field works
done
()
self
.
User
.
create
({
username
:
'user2'
,
email
:
[
'bar@baz.com'
]}).
success
(
function
(
defaultUser
){
expect
(
defaultUser
.
document
).
to
.
deep
.
equal
({
default
:
'value'
})
done
()
})
})
})
})
})
.
error
(
console
.
log
)
.
error
(
console
.
log
)
...
...
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