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 9e081439
authored
Apr 01, 2015
by
Ruben Bridgewater
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor more tests
1 parent
e45a8d3a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
105 deletions
test/integration/dialects/postgres/dao.test.js
test/integration/instance/update.test.js
test/integration/instance/values.test.js
test/integration/dialects/postgres/dao.test.js
View file @
9e08143
...
@@ -13,7 +13,7 @@ chai.config.includeStack = true;
...
@@ -13,7 +13,7 @@ chai.config.includeStack = true;
if
(
dialect
.
match
(
/^postgres/
))
{
if
(
dialect
.
match
(
/^postgres/
))
{
describe
(
'[POSTGRES Specific] DAO'
,
function
()
{
describe
(
'[POSTGRES Specific] DAO'
,
function
()
{
beforeEach
(
function
(
done
)
{
beforeEach
(
function
()
{
this
.
sequelize
.
options
.
quoteIdentifiers
=
true
;
this
.
sequelize
.
options
.
quoteIdentifiers
=
true
;
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
,
username
:
DataTypes
.
STRING
,
...
@@ -31,20 +31,16 @@ if (dialect.match(/^postgres/)) {
...
@@ -31,20 +31,16 @@ if (dialect.match(/^postgres/)) {
available_amount
:
DataTypes
.
RANGE
,
available_amount
:
DataTypes
.
RANGE
,
holidays
:
DataTypes
.
ARRAY
(
DataTypes
.
RANGE
(
DataTypes
.
DATE
))
holidays
:
DataTypes
.
ARRAY
(
DataTypes
.
RANGE
(
DataTypes
.
DATE
))
});
});
this
.
User
.
sync
({
force
:
true
}).
success
(
function
()
{
return
this
.
User
.
sync
({
force
:
true
});
done
();
});
});
});
afterEach
(
function
(
done
)
{
afterEach
(
function
()
{
this
.
sequelize
.
options
.
quoteIdentifiers
=
true
;
this
.
sequelize
.
options
.
quoteIdentifiers
=
true
;
done
();
});
});
it
(
'should be able to search within an array'
,
function
(
done
)
{
it
(
'should be able to search within an array'
,
function
()
{
this
.
User
.
a
ll
({
where
:
{
email
:
[
'hello'
,
'world'
]},
attributes
:
[
'id'
,
'username'
,
'email'
,
'settings'
,
'document'
,
'phones'
,
'emergency_contact'
,
'friends'
]}).
on
(
'sql'
,
function
(
sql
)
{
return
this
.
User
.
findA
ll
({
where
:
{
email
:
[
'hello'
,
'world'
]},
attributes
:
[
'id'
,
'username'
,
'email'
,
'settings'
,
'document'
,
'phones'
,
'emergency_contact'
,
'friends'
]}).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
to
.
equal
(
'SELECT "id", "username", "email", "settings", "document", "phones", "emergency_contact", "friends" FROM "Users" AS "User" WHERE "User"."email" = ARRAY[\'hello\',\'world\']::TEXT[];'
);
expect
(
sql
).
to
.
equal
(
'SELECT "id", "username", "email", "settings", "document", "phones", "emergency_contact", "friends" FROM "Users" AS "User" WHERE "User"."email" = ARRAY[\'hello\',\'world\']::TEXT[];'
);
done
();
});
});
});
});
...
@@ -72,17 +68,16 @@ if (dialect.match(/^postgres/)) {
...
@@ -72,17 +68,16 @@ if (dialect.match(/^postgres/)) {
});
});
});
});
it
(
'should be able to find a record while searching in an array'
,
function
(
done
)
{
it
(
'should be able to find a record while searching in an array'
,
function
()
{
var
self
=
this
;
var
self
=
this
;
this
.
User
.
bulkCreate
([
return
this
.
User
.
bulkCreate
([
{
username
:
'bob'
,
email
:
[
'myemail@email.com'
]},
{
username
:
'bob'
,
email
:
[
'myemail@email.com'
]},
{
username
:
'tony'
,
email
:
[
'wrongemail@email.com'
]}
{
username
:
'tony'
,
email
:
[
'wrongemail@email.com'
]}
]).
success
(
function
()
{
]).
then
(
function
()
{
self
.
User
.
all
({
where
:
{
email
:
[
'myemail@email.com'
]}}).
success
(
function
(
user
)
{
return
self
.
User
.
findAll
({
where
:
{
email
:
[
'myemail@email.com'
]}}).
then
(
function
(
user
)
{
expect
(
user
).
to
.
be
.
instanceof
(
Array
);
expect
(
user
).
to
.
be
.
instanceof
(
Array
);
expect
(
user
).
to
.
have
.
length
(
1
);
expect
(
user
).
to
.
have
.
length
(
1
);
expect
(
user
[
0
].
username
).
to
.
equal
(
'bob'
);
expect
(
user
[
0
].
username
).
to
.
equal
(
'bob'
);
done
();
});
});
});
});
});
});
...
@@ -318,31 +313,27 @@ if (dialect.match(/^postgres/)) {
...
@@ -318,31 +313,27 @@ if (dialect.match(/^postgres/)) {
});
});
describe
(
'enums'
,
function
()
{
describe
(
'enums'
,
function
()
{
it
(
'should be able to ignore enum types that already exist'
,
function
(
done
)
{
it
(
'should be able to ignore enum types that already exist'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'UserEnums'
,
{
var
User
=
this
.
sequelize
.
define
(
'UserEnums'
,
{
mood
:
DataTypes
.
ENUM
(
'happy'
,
'sad'
,
'meh'
)
mood
:
DataTypes
.
ENUM
(
'happy'
,
'sad'
,
'meh'
)
});
});
User
.
sync
({
force
:
true
}).
success
(
function
()
{
return
User
.
sync
({
force
:
true
}).
then
(
function
()
{
User
.
sync
().
success
(
function
()
{
return
User
.
sync
();
done
();
});
});
});
});
});
it
(
'should be able to create/drop enums multiple times'
,
function
(
done
)
{
it
(
'should be able to create/drop enums multiple times'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'UserEnums'
,
{
var
User
=
this
.
sequelize
.
define
(
'UserEnums'
,
{
mood
:
DataTypes
.
ENUM
(
'happy'
,
'sad'
,
'meh'
)
mood
:
DataTypes
.
ENUM
(
'happy'
,
'sad'
,
'meh'
)
});
});
User
.
sync
({
force
:
true
}).
success
(
function
()
{
return
User
.
sync
({
force
:
true
}).
then
(
function
()
{
User
.
sync
({
force
:
true
}).
success
(
function
()
{
return
User
.
sync
({
force
:
true
});
done
();
});
});
});
});
});
it
(
'should be able to create/drop multiple enums multiple times'
,
function
(
done
)
{
it
(
'should be able to create/drop multiple enums multiple times'
,
function
()
{
var
DummyModel
=
this
.
sequelize
.
define
(
'Dummy-pg'
,
{
var
DummyModel
=
this
.
sequelize
.
define
(
'Dummy-pg'
,
{
username
:
DataTypes
.
STRING
,
username
:
DataTypes
.
STRING
,
theEnumOne
:
{
theEnumOne
:
{
...
@@ -363,16 +354,11 @@ if (dialect.match(/^postgres/)) {
...
@@ -363,16 +354,11 @@ if (dialect.match(/^postgres/)) {
}
}
});
});
DummyModel
.
sync
({
force
:
true
}).
done
(
function
(
err
)
{
return
DummyModel
.
sync
({
force
:
true
}).
then
(
function
()
{
expect
(
err
).
not
.
to
.
be
.
ok
;
// now sync one more time:
// now sync one more time:
DummyModel
.
sync
({
force
:
true
}).
done
(
function
(
err
)
{
return
DummyModel
.
sync
({
force
:
true
}).
then
(
function
()
{
expect
(
err
).
not
.
to
.
be
.
ok
;
// sync without dropping
// sync without dropping
DummyModel
.
sync
().
done
(
function
(
err
)
{
return
DummyModel
.
sync
();
expect
(
err
).
not
.
to
.
be
.
ok
;
done
();
});
});
});
});
});
});
});
...
@@ -387,12 +373,12 @@ if (dialect.match(/^postgres/)) {
...
@@ -387,12 +373,12 @@ if (dialect.match(/^postgres/)) {
done
();
done
();
});
});
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
sync
({
force
:
true
}).
then
(
function
()
{
User
=
self
.
sequelize
.
define
(
'UserEnums'
,
{
User
=
self
.
sequelize
.
define
(
'UserEnums'
,
{
mood
:
DataTypes
.
ENUM
(
'neutral'
,
'happy'
,
'sad'
,
'ecstatic'
,
'meh'
,
'joyful'
)
mood
:
DataTypes
.
ENUM
(
'neutral'
,
'happy'
,
'sad'
,
'ecstatic'
,
'meh'
,
'joyful'
)
});
});
User
.
sync
().
success
(
function
()
{
User
.
sync
().
then
(
function
()
{
expect
(
User
.
rawAttributes
.
mood
.
values
).
to
.
deep
.
equal
([
'neutral'
,
'happy'
,
'sad'
,
'ecstatic'
,
'meh'
,
'joyful'
]);
expect
(
User
.
rawAttributes
.
mood
.
values
).
to
.
deep
.
equal
([
'neutral'
,
'happy'
,
'sad'
,
'ecstatic'
,
'meh'
,
'joyful'
]);
_done
();
_done
();
}).
on
(
'sql'
,
function
(
sql
)
{
}).
on
(
'sql'
,
function
(
sql
)
{
...
@@ -415,72 +401,64 @@ if (dialect.match(/^postgres/)) {
...
@@ -415,72 +401,64 @@ if (dialect.match(/^postgres/)) {
describe
(
'integers'
,
function
()
{
describe
(
'integers'
,
function
()
{
describe
(
'integer'
,
function
()
{
describe
(
'integer'
,
function
()
{
beforeEach
(
function
(
done
)
{
beforeEach
(
function
()
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
aNumber
:
DataTypes
.
INTEGER
aNumber
:
DataTypes
.
INTEGER
});
});
this
.
User
.
sync
({
force
:
true
}).
success
(
function
()
{
return
this
.
User
.
sync
({
force
:
true
});
done
();
});
});
});
it
(
'positive'
,
function
(
done
)
{
it
(
'positive'
,
function
()
{
var
User
=
this
.
User
;
var
User
=
this
.
User
;
User
.
create
({
aNumber
:
2147483647
}).
success
(
function
(
user
)
{
return
User
.
create
({
aNumber
:
2147483647
}).
then
(
function
(
user
)
{
expect
(
user
.
aNumber
).
to
.
equal
(
2147483647
);
expect
(
user
.
aNumber
).
to
.
equal
(
2147483647
);
User
.
find
({
where
:
{
aNumber
:
2147483647
}}).
success
(
function
(
_user
)
{
return
User
.
find
({
where
:
{
aNumber
:
2147483647
}}).
then
(
function
(
_user
)
{
expect
(
_user
.
aNumber
).
to
.
equal
(
2147483647
);
expect
(
_user
.
aNumber
).
to
.
equal
(
2147483647
);
done
();
});
});
});
});
});
});
it
(
'negative'
,
function
(
done
)
{
it
(
'negative'
,
function
()
{
var
User
=
this
.
User
;
var
User
=
this
.
User
;
User
.
create
({
aNumber
:
-
2147483647
}).
success
(
function
(
user
)
{
return
User
.
create
({
aNumber
:
-
2147483647
}).
then
(
function
(
user
)
{
expect
(
user
.
aNumber
).
to
.
equal
(
-
2147483647
);
expect
(
user
.
aNumber
).
to
.
equal
(
-
2147483647
);
User
.
find
({
where
:
{
aNumber
:
-
2147483647
}}).
success
(
function
(
_user
)
{
return
User
.
find
({
where
:
{
aNumber
:
-
2147483647
}}).
then
(
function
(
_user
)
{
expect
(
_user
.
aNumber
).
to
.
equal
(
-
2147483647
);
expect
(
_user
.
aNumber
).
to
.
equal
(
-
2147483647
);
done
();
});
});
});
});
});
});
});
});
describe
(
'bigint'
,
function
()
{
describe
(
'bigint'
,
function
()
{
beforeEach
(
function
(
done
)
{
beforeEach
(
function
()
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
aNumber
:
DataTypes
.
BIGINT
aNumber
:
DataTypes
.
BIGINT
});
});
this
.
User
.
sync
({
force
:
true
}).
success
(
function
()
{
return
this
.
User
.
sync
({
force
:
true
});
done
();
});
});
});
it
(
'positive'
,
function
(
done
)
{
it
(
'positive'
,
function
()
{
var
User
=
this
.
User
;
var
User
=
this
.
User
;
User
.
create
({
aNumber
:
'9223372036854775807'
}).
success
(
function
(
user
)
{
return
User
.
create
({
aNumber
:
'9223372036854775807'
}).
then
(
function
(
user
)
{
expect
(
user
.
aNumber
).
to
.
equal
(
'9223372036854775807'
);
expect
(
user
.
aNumber
).
to
.
equal
(
'9223372036854775807'
);
User
.
find
({
where
:
{
aNumber
:
'9223372036854775807'
}}).
success
(
function
(
_user
)
{
return
User
.
find
({
where
:
{
aNumber
:
'9223372036854775807'
}}).
then
(
function
(
_user
)
{
expect
(
_user
.
aNumber
).
to
.
equal
(
'9223372036854775807'
);
expect
(
_user
.
aNumber
).
to
.
equal
(
'9223372036854775807'
);
done
();
});
});
});
});
});
});
it
(
'negative'
,
function
(
done
)
{
it
(
'negative'
,
function
()
{
var
User
=
this
.
User
;
var
User
=
this
.
User
;
User
.
create
({
aNumber
:
'-9223372036854775807'
}).
success
(
function
(
user
)
{
return
User
.
create
({
aNumber
:
'-9223372036854775807'
}).
then
(
function
(
user
)
{
expect
(
user
.
aNumber
).
to
.
equal
(
'-9223372036854775807'
);
expect
(
user
.
aNumber
).
to
.
equal
(
'-9223372036854775807'
);
User
.
find
({
where
:
{
aNumber
:
'-9223372036854775807'
}}).
success
(
function
(
_user
)
{
return
User
.
find
({
where
:
{
aNumber
:
'-9223372036854775807'
}}).
then
(
function
(
_user
)
{
expect
(
_user
.
aNumber
).
to
.
equal
(
'-9223372036854775807'
);
expect
(
_user
.
aNumber
).
to
.
equal
(
'-9223372036854775807'
);
done
();
});
});
});
});
});
});
...
@@ -488,34 +466,30 @@ if (dialect.match(/^postgres/)) {
...
@@ -488,34 +466,30 @@ if (dialect.match(/^postgres/)) {
});
});
describe
(
'timestamps'
,
function
()
{
describe
(
'timestamps'
,
function
()
{
beforeEach
(
function
(
done
)
{
beforeEach
(
function
()
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
dates
:
DataTypes
.
ARRAY
(
DataTypes
.
DATE
)
dates
:
DataTypes
.
ARRAY
(
DataTypes
.
DATE
)
});
});
this
.
User
.
sync
({
force
:
true
}).
success
(
function
()
{
return
this
.
User
.
sync
({
force
:
true
});
done
();
});
});
});
it
(
'should use postgres "TIMESTAMP WITH TIME ZONE" instead of "DATETIME"'
,
function
(
done
)
{
it
(
'should use postgres "TIMESTAMP WITH TIME ZONE" instead of "DATETIME"'
,
function
()
{
this
.
User
.
create
({
return
this
.
User
.
create
({
dates
:
[]
dates
:
[]
}).
on
(
'sql'
,
function
(
sql
)
{
}).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
.
indexOf
(
'TIMESTAMP WITH TIME ZONE'
)).
to
.
be
.
greaterThan
(
0
);
expect
(
sql
.
indexOf
(
'TIMESTAMP WITH TIME ZONE'
)).
to
.
be
.
greaterThan
(
0
);
done
();
});
});
});
});
});
});
describe
(
'model'
,
function
()
{
describe
(
'model'
,
function
()
{
it
(
'create handles array correctly'
,
function
(
done
)
{
it
(
'create handles array correctly'
,
function
()
{
this
.
User
return
this
.
User
.
create
({
username
:
'user'
,
email
:
[
'foo@bar.com'
,
'bar@baz.com'
]
})
.
create
({
username
:
'user'
,
email
:
[
'foo@bar.com'
,
'bar@baz.com'
]
})
.
success
(
function
(
oldUser
)
{
.
then
(
function
(
oldUser
)
{
expect
(
oldUser
.
email
).
to
.
contain
.
members
([
'foo@bar.com'
,
'bar@baz.com'
]);
expect
(
oldUser
.
email
).
to
.
contain
.
members
([
'foo@bar.com'
,
'bar@baz.com'
]);
done
();
})
})
.
error
(
function
(
err
)
{
.
catch
(
function
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
});
});
});
});
...
@@ -575,7 +549,7 @@ if (dialect.match(/^postgres/)) {
...
@@ -575,7 +549,7 @@ if (dialect.match(/^postgres/)) {
// Check to see if updating an hstore field works
// Check to see if updating an hstore field works
return
self
.
User
.
update
({
settings
:
{
should
:
'update'
,
to
:
'this'
,
first
:
'place'
}},
{
where
:
newUser
.
identifiers
}).
then
(
function
()
{
return
self
.
User
.
update
({
settings
:
{
should
:
'update'
,
to
:
'this'
,
first
:
'place'
}},
{
where
:
newUser
.
identifiers
}).
then
(
function
()
{
return
newUser
.
reload
().
success
(
function
()
{
return
newUser
.
reload
().
then
(
function
()
{
// Postgres always returns keys in alphabetical order (ascending)
// Postgres always returns keys in alphabetical order (ascending)
expect
(
newUser
.
settings
).
to
.
deep
.
equal
({
first
:
'place'
,
should
:
'update'
,
to
:
'this'
});
expect
(
newUser
.
settings
).
to
.
deep
.
equal
({
first
:
'place'
,
should
:
'update'
,
to
:
'this'
});
});
});
...
@@ -622,10 +596,10 @@ if (dialect.match(/^postgres/)) {
...
@@ -622,10 +596,10 @@ if (dialect.match(/^postgres/)) {
});
});
});
});
it
(
'should read hstore correctly from multiple rows'
,
function
(
done
)
{
it
(
'should read hstore correctly from multiple rows'
,
function
()
{
var
self
=
this
;
var
self
=
this
;
self
.
User
return
self
.
User
.
create
({
username
:
'user1'
,
email
:
[
'foo@bar.com'
],
settings
:
{
test
:
'"value"'
}})
.
create
({
username
:
'user1'
,
email
:
[
'foo@bar.com'
],
settings
:
{
test
:
'"value"'
}})
.
then
(
function
()
{
.
then
(
function
()
{
return
self
.
User
.
create
({
username
:
'user2'
,
email
:
[
'foo2@bar.com'
],
settings
:
{
another
:
'"example"'
}});
return
self
.
User
.
create
({
username
:
'user2'
,
email
:
[
'foo2@bar.com'
],
settings
:
{
another
:
'"example"'
}});
...
@@ -637,10 +611,8 @@ if (dialect.match(/^postgres/)) {
...
@@ -637,10 +611,8 @@ if (dialect.match(/^postgres/)) {
.
then
(
function
(
users
)
{
.
then
(
function
(
users
)
{
expect
(
users
[
0
].
settings
).
to
.
deep
.
equal
({
test
:
'"value"'
});
expect
(
users
[
0
].
settings
).
to
.
deep
.
equal
({
test
:
'"value"'
});
expect
(
users
[
1
].
settings
).
to
.
deep
.
equal
({
another
:
'"example"'
});
expect
(
users
[
1
].
settings
).
to
.
deep
.
equal
({
another
:
'"example"'
});
done
();
})
})
.
error
(
console
.
log
);
.
catch
(
console
.
log
);
});
});
it
(
'should read hstore correctly from included models as well'
,
function
()
{
it
(
'should read hstore correctly from included models as well'
,
function
()
{
...
@@ -763,7 +735,7 @@ if (dialect.match(/^postgres/)) {
...
@@ -763,7 +735,7 @@ if (dialect.match(/^postgres/)) {
// Check to see if updating a range field works
// Check to see if updating a range field works
return
User
.
update
({
course_period
:
period
},
{
where
:
newUser
.
identifiers
}).
then
(
function
()
{
return
User
.
update
({
course_period
:
period
},
{
where
:
newUser
.
identifiers
}).
then
(
function
()
{
return
newUser
.
reload
().
success
(
function
()
{
return
newUser
.
reload
().
then
(
function
()
{
expect
(
newUser
.
course_period
[
0
]
instanceof
Date
).
to
.
be
.
ok
;
expect
(
newUser
.
course_period
[
0
]
instanceof
Date
).
to
.
be
.
ok
;
expect
(
newUser
.
course_period
[
1
]
instanceof
Date
).
to
.
be
.
ok
;
expect
(
newUser
.
course_period
[
1
]
instanceof
Date
).
to
.
be
.
ok
;
expect
(
newUser
.
course_period
[
0
]).
to
.
equalTime
(
period
[
0
]);
// lower bound
expect
(
newUser
.
course_period
[
0
]).
to
.
equalTime
(
period
[
0
]);
// lower bound
...
@@ -859,7 +831,7 @@ if (dialect.match(/^postgres/)) {
...
@@ -859,7 +831,7 @@ if (dialect.match(/^postgres/)) {
expect
(
users
[
1
].
course_period
[
1
]).
to
.
equalTime
(
periods
[
1
][
1
]);
// upper bound
expect
(
users
[
1
].
course_period
[
1
]).
to
.
equalTime
(
periods
[
1
][
1
]);
// upper bound
expect
(
users
[
1
].
course_period
.
inclusive
).
to
.
deep
.
equal
([
false
,
false
]);
// not inclusive
expect
(
users
[
1
].
course_period
.
inclusive
).
to
.
deep
.
equal
([
false
,
false
]);
// not inclusive
})
})
.
error
(
console
.
log
);
.
catch
(
console
.
log
);
});
});
it
(
'should read range correctly from included models as well'
,
function
()
{
it
(
'should read range correctly from included models as well'
,
function
()
{
...
@@ -897,7 +869,7 @@ if (dialect.match(/^postgres/)) {
...
@@ -897,7 +869,7 @@ if (dialect.match(/^postgres/)) {
});
});
describe
(
'[POSTGRES] Unquoted identifiers'
,
function
()
{
describe
(
'[POSTGRES] Unquoted identifiers'
,
function
()
{
it
(
'can insert and select'
,
function
(
done
)
{
it
(
'can insert and select'
,
function
()
{
var
self
=
this
;
var
self
=
this
;
this
.
sequelize
.
options
.
quoteIdentifiers
=
false
;
this
.
sequelize
.
options
.
quoteIdentifiers
=
false
;
this
.
sequelize
.
getQueryInterface
().
QueryGenerator
.
options
.
quoteIdentifiers
=
false
;
this
.
sequelize
.
getQueryInterface
().
QueryGenerator
.
options
.
quoteIdentifiers
=
false
;
...
@@ -909,10 +881,10 @@ if (dialect.match(/^postgres/)) {
...
@@ -909,10 +881,10 @@ if (dialect.match(/^postgres/)) {
quoteIdentifiers
:
false
quoteIdentifiers
:
false
});
});
this
.
User
.
sync
({
force
:
true
}).
success
(
function
()
{
return
this
.
User
.
sync
({
force
:
true
}).
then
(
function
()
{
self
.
User
self
.
User
.
create
({
username
:
'user'
,
fullName
:
'John Smith'
})
.
create
({
username
:
'user'
,
fullName
:
'John Smith'
})
.
success
(
function
(
user
)
{
.
then
(
function
(
user
)
{
// We can insert into a table with non-quoted identifiers
// We can insert into a table with non-quoted identifiers
expect
(
user
.
id
).
to
.
exist
;
expect
(
user
.
id
).
to
.
exist
;
expect
(
user
.
id
).
not
.
to
.
be
.
null
;
expect
(
user
.
id
).
not
.
to
.
be
.
null
;
...
@@ -920,27 +892,25 @@ if (dialect.match(/^postgres/)) {
...
@@ -920,27 +892,25 @@ if (dialect.match(/^postgres/)) {
expect
(
user
.
fullName
).
to
.
equal
(
'John Smith'
);
expect
(
user
.
fullName
).
to
.
equal
(
'John Smith'
);
// We can query by non-quoted identifiers
// We can query by non-quoted identifiers
self
.
User
.
find
({
return
self
.
User
.
find
({
where
:
{
fullName
:
'John Smith'
}
where
:
{
fullName
:
'John Smith'
}
})
})
.
success
(
function
(
user2
)
{
.
then
(
function
(
user2
)
{
// We can map values back to non-quoted identifiers
// We can map values back to non-quoted identifiers
expect
(
user2
.
id
).
to
.
equal
(
user
.
id
);
expect
(
user2
.
id
).
to
.
equal
(
user
.
id
);
expect
(
user2
.
username
).
to
.
equal
(
'user'
);
expect
(
user2
.
username
).
to
.
equal
(
'user'
);
expect
(
user2
.
fullName
).
to
.
equal
(
'John Smith'
);
expect
(
user2
.
fullName
).
to
.
equal
(
'John Smith'
);
// We can query and aggregate by non-quoted identifiers
// We can query and aggregate by non-quoted identifiers
self
.
User
return
self
.
User
.
count
({
.
count
({
where
:
{
fullName
:
'John Smith'
}
where
:
{
fullName
:
'John Smith'
}
})
})
.
success
(
function
(
count
)
{
.
then
(
function
(
count
)
{
self
.
sequelize
.
options
.
quoteIndentifiers
=
true
;
self
.
sequelize
.
options
.
quoteIndentifiers
=
true
;
self
.
sequelize
.
getQueryInterface
().
QueryGenerator
.
options
.
quoteIdentifiers
=
true
;
self
.
sequelize
.
getQueryInterface
().
QueryGenerator
.
options
.
quoteIdentifiers
=
true
;
self
.
sequelize
.
options
.
logging
=
false
;
self
.
sequelize
.
options
.
logging
=
false
;
expect
(
count
).
to
.
equal
(
1
);
expect
(
count
).
to
.
equal
(
1
);
done
();
});
});
});
});
});
});
...
...
test/integration/instance/update.test.js
View file @
9e08143
...
@@ -359,7 +359,7 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
...
@@ -359,7 +359,7 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
,
oldUpdatedAt
=
user
.
updatedAt
,
oldUpdatedAt
=
user
.
updatedAt
,
oldIdentifier
=
user
.
identifier
;
,
oldIdentifier
=
user
.
identifier
;
return
Promise
.
delay
(
1000
).
then
(
function
()
{
return
this
.
sequelize
.
Promise
.
delay
(
1000
).
then
(
function
()
{
return
user
.
update
({
return
user
.
update
({
name
:
'foobar'
,
name
:
'foobar'
,
createdAt
:
new
Date
(
2000
,
1
,
1
),
createdAt
:
new
Date
(
2000
,
1
,
1
),
...
...
test/integration/instance/values.test.js
View file @
9e08143
...
@@ -295,7 +295,7 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
...
@@ -295,7 +295,7 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
expect
(
product
.
toJSON
()).
to
.
deep
.
equal
({
withTaxes
:
1250
,
price
:
1000
,
id
:
null
});
expect
(
product
.
toJSON
()).
to
.
deep
.
equal
({
withTaxes
:
1250
,
price
:
1000
,
id
:
null
});
});
});
it
(
'should work with save'
,
function
(
done
)
{
it
(
'should work with save'
,
function
()
{
var
Contact
=
this
.
sequelize
.
define
(
'Contact'
,
{
var
Contact
=
this
.
sequelize
.
define
(
'Contact'
,
{
first
:
{
type
:
Sequelize
.
STRING
},
first
:
{
type
:
Sequelize
.
STRING
},
last
:
{
type
:
Sequelize
.
STRING
},
last
:
{
type
:
Sequelize
.
STRING
},
...
@@ -311,7 +311,7 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
...
@@ -311,7 +311,7 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
}
}
});
});
this
.
sequelize
.
sync
().
done
(
function
()
{
return
this
.
sequelize
.
sync
().
then
(
function
()
{
var
contact
=
Contact
.
build
({
var
contact
=
Contact
.
build
({
first
:
'My'
,
first
:
'My'
,
last
:
'Name'
,
last
:
'Name'
,
...
@@ -319,10 +319,8 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
...
@@ -319,10 +319,8 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
});
});
expect
(
contact
.
get
(
'tags'
)).
to
.
deep
.
equal
([
'yes'
,
'no'
]);
expect
(
contact
.
get
(
'tags'
)).
to
.
deep
.
equal
([
'yes'
,
'no'
]);
contact
.
save
().
done
(
function
(
err
,
me
)
{
return
contact
.
save
().
then
(
function
(
me
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
expect
(
me
.
get
(
'tags'
)).
to
.
deep
.
equal
([
'yes'
,
'no'
]);
expect
(
me
.
get
(
'tags'
)).
to
.
deep
.
equal
([
'yes'
,
'no'
]);
done
();
});
});
});
});
});
});
...
@@ -380,18 +378,16 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
...
@@ -380,18 +378,16 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
});
});
describe
(
'changed'
,
function
()
{
describe
(
'changed'
,
function
()
{
it
(
'should return false if object was built from database'
,
function
(
done
)
{
it
(
'should return false if object was built from database'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
{
type
:
DataTypes
.
STRING
}
name
:
{
type
:
DataTypes
.
STRING
}
});
});
User
.
sync
().
done
(
function
()
{
return
User
.
sync
().
then
(
function
()
{
User
.
create
({
name
:
'Jan Meier'
}).
done
(
function
(
err
,
user
)
{
return
User
.
create
({
name
:
'Jan Meier'
}).
then
(
function
(
user
)
{
expect
(
err
).
not
.
to
.
be
.
ok
;
expect
(
user
.
changed
(
'name'
)).
to
.
be
.
false
;
expect
(
user
.
changed
(
'name'
)).
to
.
be
.
false
;
expect
(
user
.
changed
()).
not
.
to
.
be
.
ok
;
expect
(
user
.
changed
()).
not
.
to
.
be
.
ok
;
expect
(
user
.
isDirty
).
to
.
be
.
false
;
expect
(
user
.
isDirty
).
to
.
be
.
false
;
done
();
});
});
});
});
});
});
...
@@ -410,12 +406,12 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
...
@@ -410,12 +406,12 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
expect
(
user
.
isDirty
).
to
.
be
.
true
;
expect
(
user
.
isDirty
).
to
.
be
.
true
;
});
});
it
(
'should return false immediately after saving'
,
function
(
done
)
{
it
(
'should return false immediately after saving'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
{
type
:
DataTypes
.
STRING
}
name
:
{
type
:
DataTypes
.
STRING
}
});
});
User
.
sync
().
done
(
function
()
{
return
User
.
sync
().
then
(
function
()
{
var
user
=
User
.
build
({
var
user
=
User
.
build
({
name
:
'Jan Meier'
name
:
'Jan Meier'
});
});
...
@@ -424,12 +420,10 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
...
@@ -424,12 +420,10 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
expect
(
user
.
changed
()).
to
.
be
.
ok
;
expect
(
user
.
changed
()).
to
.
be
.
ok
;
expect
(
user
.
isDirty
).
to
.
be
.
true
;
expect
(
user
.
isDirty
).
to
.
be
.
true
;
user
.
save
().
done
(
function
(
err
)
{
return
user
.
save
().
then
(
function
()
{
expect
(
err
).
not
.
to
.
be
.
ok
;
expect
(
user
.
changed
(
'name'
)).
to
.
be
.
false
;
expect
(
user
.
changed
(
'name'
)).
to
.
be
.
false
;
expect
(
user
.
changed
()).
not
.
to
.
be
.
ok
;
expect
(
user
.
changed
()).
not
.
to
.
be
.
ok
;
expect
(
user
.
isDirty
).
to
.
be
.
false
;
expect
(
user
.
isDirty
).
to
.
be
.
false
;
done
();
});
});
});
});
});
});
...
@@ -472,7 +466,6 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
...
@@ -472,7 +466,6 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
expect
(
changed
).
to
.
be
.
ok
;
expect
(
changed
).
to
.
be
.
ok
;
expect
(
changed
.
length
).
to
.
be
.
ok
;
expect
(
changed
.
length
).
to
.
be
.
ok
;
expect
(
changed
.
indexOf
(
'name'
)
>
-
1
).
to
.
be
.
ok
;
expect
(
changed
.
indexOf
(
'name'
)
>
-
1
).
to
.
be
.
ok
;
expect
(
user
.
changed
()).
not
.
to
.
be
.
ok
;
expect
(
user
.
changed
()).
not
.
to
.
be
.
ok
;
});
});
});
});
...
...
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