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 3568ced8
authored
Apr 01, 2015
by
Ruben Bridgewater
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor more tests
1 parent
0d383338
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
75 deletions
test/integration/dialects/mysql/connector-manager.test.js
test/integration/dialects/sqlite/dao-factory.test.js
test/integration/dialects/sqlite/dao.test.js
test/integration/model/create.test.js
test/integration/model/findAll.test.js
test/integration/promise.test.js
test/integration/dialects/mysql/connector-manager.test.js
View file @
3568ced
...
@@ -14,9 +14,9 @@ if (Support.dialectIsMySQL()) {
...
@@ -14,9 +14,9 @@ if (Support.dialectIsMySQL()) {
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
})
,
spy
=
sinon
.
spy
();
,
spy
=
sinon
.
spy
();
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
sync
({
force
:
true
}).
then
(
function
()
{
User
.
create
({
username
:
'user1'
}).
on
(
'success'
,
function
()
{
User
.
create
({
username
:
'user1'
}).
then
(
function
()
{
User
.
count
().
on
(
'success'
,
function
(
count
)
{
User
.
count
().
then
(
function
(
count
)
{
expect
(
count
).
to
.
equal
(
1
);
expect
(
count
).
to
.
equal
(
1
);
spy
();
spy
();
...
...
test/integration/dialects/sqlite/dao-factory.test.js
View file @
3568ced
...
@@ -12,147 +12,131 @@ chai.config.includeStack = true;
...
@@ -12,147 +12,131 @@ chai.config.includeStack = true;
if
(
dialect
===
'sqlite'
)
{
if
(
dialect
===
'sqlite'
)
{
describe
(
'[SQLITE Specific] DAOFactory'
,
function
()
{
describe
(
'[SQLITE Specific] DAOFactory'
,
function
()
{
after
(
function
(
done
)
{
after
(
function
()
{
this
.
sequelize
.
options
.
storage
=
':memory:'
;
this
.
sequelize
.
options
.
storage
=
':memory:'
;
done
();
});
});
beforeEach
(
function
(
done
)
{
beforeEach
(
function
()
{
this
.
sequelize
.
options
.
storage
=
dbFile
;
this
.
sequelize
.
options
.
storage
=
dbFile
;
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
age
:
DataTypes
.
INTEGER
,
age
:
DataTypes
.
INTEGER
,
name
:
DataTypes
.
STRING
,
name
:
DataTypes
.
STRING
,
bio
:
DataTypes
.
TEXT
bio
:
DataTypes
.
TEXT
});
});
this
.
User
.
sync
({
force
:
true
}).
success
(
function
()
{
return
this
.
User
.
sync
({
force
:
true
});
done
();
});
});
});
storages
.
forEach
(
function
(
storage
)
{
storages
.
forEach
(
function
(
storage
)
{
describe
(
'with storage "'
+
storage
+
'"'
,
function
()
{
describe
(
'with storage "'
+
storage
+
'"'
,
function
()
{
after
(
function
(
done
)
{
after
(
function
()
{
if
(
storage
===
dbFile
)
{
if
(
storage
===
dbFile
)
{
require
(
'fs'
).
writeFile
(
dbFile
,
''
,
function
()
{
require
(
'fs'
).
writeFileSync
(
dbFile
,
''
);
done
();
});
}
}
});
});
describe
(
'create'
,
function
()
{
describe
(
'create'
,
function
()
{
it
(
'creates a table entry'
,
function
(
done
)
{
it
(
'creates a table entry'
,
function
()
{
var
self
=
this
;
var
self
=
this
;
this
.
User
.
create
({
age
:
21
,
name
:
'John Wayne'
,
bio
:
'noot noot'
}).
success
(
function
(
user
)
{
return
this
.
User
.
create
({
age
:
21
,
name
:
'John Wayne'
,
bio
:
'noot noot'
}).
then
(
function
(
user
)
{
expect
(
user
.
age
).
to
.
equal
(
21
);
expect
(
user
.
age
).
to
.
equal
(
21
);
expect
(
user
.
name
).
to
.
equal
(
'John Wayne'
);
expect
(
user
.
name
).
to
.
equal
(
'John Wayne'
);
expect
(
user
.
bio
).
to
.
equal
(
'noot noot'
);
expect
(
user
.
bio
).
to
.
equal
(
'noot noot'
);
self
.
User
.
all
().
success
(
function
(
users
)
{
return
self
.
User
.
findAll
().
then
(
function
(
users
)
{
var
usernames
=
users
.
map
(
function
(
user
)
{
var
usernames
=
users
.
map
(
function
(
user
)
{
return
user
.
name
;
return
user
.
name
;
});
});
expect
(
usernames
).
to
.
contain
(
'John Wayne'
);
expect
(
usernames
).
to
.
contain
(
'John Wayne'
);
done
();
});
});
});
});
});
});
it
(
'should allow the creation of an object with options as attribute'
,
function
(
done
)
{
it
(
'should allow the creation of an object with options as attribute'
,
function
()
{
var
Person
=
this
.
sequelize
.
define
(
'Person'
,
{
var
Person
=
this
.
sequelize
.
define
(
'Person'
,
{
name
:
DataTypes
.
STRING
,
name
:
DataTypes
.
STRING
,
options
:
DataTypes
.
TEXT
options
:
DataTypes
.
TEXT
});
});
Person
.
sync
({
force
:
true
}).
success
(
function
()
{
return
Person
.
sync
({
force
:
true
}).
then
(
function
()
{
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
});
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
});
Person
.
create
({
return
Person
.
create
({
name
:
'John Doe'
,
name
:
'John Doe'
,
options
:
options
options
:
options
}).
success
(
function
(
people
)
{
}).
then
(
function
(
people
)
{
expect
(
people
.
options
).
to
.
deep
.
equal
(
options
);
expect
(
people
.
options
).
to
.
deep
.
equal
(
options
);
done
();
});
});
});
});
});
});
it
(
'should allow the creation of an object with a boolean (true) as attribute'
,
function
(
done
)
{
it
(
'should allow the creation of an object with a boolean (true) as attribute'
,
function
()
{
var
Person
=
this
.
sequelize
.
define
(
'Person'
,
{
var
Person
=
this
.
sequelize
.
define
(
'Person'
,
{
name
:
DataTypes
.
STRING
,
name
:
DataTypes
.
STRING
,
has_swag
:
DataTypes
.
BOOLEAN
has_swag
:
DataTypes
.
BOOLEAN
});
});
Person
.
sync
({
force
:
true
}).
success
(
function
()
{
return
Person
.
sync
({
force
:
true
}).
then
(
function
()
{
Person
.
create
({
return
Person
.
create
({
name
:
'John Doe'
,
name
:
'John Doe'
,
has_swag
:
true
has_swag
:
true
}).
success
(
function
(
people
)
{
}).
then
(
function
(
people
)
{
expect
(
people
.
has_swag
).
to
.
be
.
ok
;
expect
(
people
.
has_swag
).
to
.
be
.
ok
;
done
();
});
});
});
});
});
});
it
(
'should allow the creation of an object with a boolean (false) as attribute'
,
function
(
done
)
{
it
(
'should allow the creation of an object with a boolean (false) as attribute'
,
function
()
{
var
Person
=
this
.
sequelize
.
define
(
'Person'
,
{
var
Person
=
this
.
sequelize
.
define
(
'Person'
,
{
name
:
DataTypes
.
STRING
,
name
:
DataTypes
.
STRING
,
has_swag
:
DataTypes
.
BOOLEAN
has_swag
:
DataTypes
.
BOOLEAN
});
});
Person
.
sync
({
force
:
true
}).
success
(
function
()
{
return
Person
.
sync
({
force
:
true
}).
then
(
function
()
{
Person
.
create
({
return
Person
.
create
({
name
:
'John Doe'
,
name
:
'John Doe'
,
has_swag
:
false
has_swag
:
false
}).
success
(
function
(
people
)
{
}).
then
(
function
(
people
)
{
expect
(
people
.
has_swag
).
to
.
not
.
be
.
ok
;
expect
(
people
.
has_swag
).
to
.
not
.
be
.
ok
;
done
();
});
});
});
});
});
});
});
});
describe
(
'.find'
,
function
()
{
describe
(
'.find'
,
function
()
{
beforeEach
(
function
(
done
)
{
beforeEach
(
function
()
{
this
.
User
.
create
({
name
:
'user'
,
bio
:
'footbar'
}).
success
(
function
()
{
return
this
.
User
.
create
({
name
:
'user'
,
bio
:
'footbar'
});
done
();
});
});
});
it
(
'finds normal lookups'
,
function
(
done
)
{
it
(
'finds normal lookups'
,
function
()
{
this
.
User
.
find
({
where
:
{
name
:
'user'
}
}).
success
(
function
(
user
)
{
return
this
.
User
.
find
({
where
:
{
name
:
'user'
}
}).
then
(
function
(
user
)
{
expect
(
user
.
name
).
to
.
equal
(
'user'
);
expect
(
user
.
name
).
to
.
equal
(
'user'
);
done
();
});
});
});
});
it
.
skip
(
'should make aliased attributes available'
,
function
(
done
)
{
it
.
skip
(
'should make aliased attributes available'
,
function
()
{
this
.
User
.
find
({
where
:
{
name
:
'user'
},
attributes
:
[
'id'
,
[
'name'
,
'username'
]]
}).
success
(
function
(
user
)
{
return
this
.
User
.
find
({
where
:
{
name
:
'user'
},
attributes
:
[
'id'
,
[
'name'
,
'username'
]]
}).
then
(
function
(
user
)
{
expect
(
user
.
username
).
to
.
equal
(
'user'
);
expect
(
user
.
username
).
to
.
equal
(
'user'
);
done
();
});
});
});
});
});
});
describe
(
'.all'
,
function
()
{
describe
(
'.all'
,
function
()
{
beforeEach
(
function
(
done
)
{
beforeEach
(
function
()
{
this
.
User
.
bulkCreate
([
return
this
.
User
.
bulkCreate
([
{
name
:
'user'
,
bio
:
'foobar'
},
{
name
:
'user'
,
bio
:
'foobar'
},
{
name
:
'user'
,
bio
:
'foobar'
}
{
name
:
'user'
,
bio
:
'foobar'
}
]).
success
(
function
()
{
]);
done
();
});
});
});
it
(
'should return all users'
,
function
(
done
)
{
it
(
'should return all users'
,
function
()
{
this
.
User
.
all
().
on
(
'success'
,
function
(
users
)
{
return
this
.
User
.
findAll
().
then
(
function
(
users
)
{
expect
(
users
).
to
.
have
.
length
(
2
);
expect
(
users
).
to
.
have
.
length
(
2
);
done
();
});
});
});
});
});
});
describe
(
'.min'
,
function
()
{
describe
(
'.min'
,
function
()
{
it
(
'should return the min value'
,
function
(
done
)
{
it
(
'should return the min value'
,
function
()
{
var
self
=
this
var
self
=
this
,
users
=
[];
,
users
=
[];
...
@@ -160,17 +144,16 @@ if (dialect === 'sqlite') {
...
@@ -160,17 +144,16 @@ if (dialect === 'sqlite') {
users
[
users
.
length
]
=
{
age
:
i
};
users
[
users
.
length
]
=
{
age
:
i
};
}
}
this
.
User
.
bulkCreate
(
users
).
success
(
function
()
{
return
this
.
User
.
bulkCreate
(
users
).
then
(
function
()
{
self
.
User
.
min
(
'age'
).
on
(
'success'
,
function
(
min
)
{
return
self
.
User
.
min
(
'age'
).
then
(
function
(
min
)
{
expect
(
min
).
to
.
equal
(
2
);
expect
(
min
).
to
.
equal
(
2
);
done
();
});
});
});
});
});
});
});
});
describe
(
'.max'
,
function
()
{
describe
(
'.max'
,
function
()
{
it
(
'should return the max value'
,
function
(
done
)
{
it
(
'should return the max value'
,
function
()
{
var
self
=
this
var
self
=
this
,
users
=
[];
,
users
=
[];
...
@@ -178,10 +161,9 @@ if (dialect === 'sqlite') {
...
@@ -178,10 +161,9 @@ if (dialect === 'sqlite') {
users
[
users
.
length
]
=
{
age
:
i
};
users
[
users
.
length
]
=
{
age
:
i
};
}
}
this
.
User
.
bulkCreate
(
users
).
success
(
function
()
{
return
this
.
User
.
bulkCreate
(
users
).
then
(
function
()
{
self
.
User
.
max
(
'age'
).
on
(
'success'
,
function
(
min
)
{
return
self
.
User
.
max
(
'age'
).
then
(
function
(
min
)
{
expect
(
min
).
to
.
equal
(
5
);
expect
(
min
).
to
.
equal
(
5
);
done
();
});
});
});
});
});
});
...
...
test/integration/dialects/sqlite/dao.test.js
View file @
3568ced
...
@@ -10,29 +10,26 @@ chai.config.includeStack = true;
...
@@ -10,29 +10,26 @@ chai.config.includeStack = true;
if
(
dialect
===
'sqlite'
)
{
if
(
dialect
===
'sqlite'
)
{
describe
(
'[SQLITE Specific] DAO'
,
function
()
{
describe
(
'[SQLITE Specific] DAO'
,
function
()
{
beforeEach
(
function
(
done
)
{
beforeEach
(
function
()
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
username
:
DataTypes
.
STRING
});
});
this
.
User
.
sync
({
force
:
true
}).
success
(
function
()
{
return
this
.
User
.
sync
({
force
:
true
});
done
();
});
});
});
describe
(
'findAll'
,
function
()
{
describe
(
'findAll'
,
function
()
{
it
(
'handles dates correctly'
,
function
(
done
)
{
it
(
'handles dates correctly'
,
function
()
{
var
self
=
this
var
self
=
this
,
user
=
this
.
User
.
build
({
username
:
'user'
});
,
user
=
this
.
User
.
build
({
username
:
'user'
});
user
.
dataValues
[
'createdAt'
]
=
new
Date
(
2011
,
4
,
4
);
user
.
dataValues
[
'createdAt'
]
=
new
Date
(
2011
,
4
,
4
);
user
.
save
().
success
(
function
()
{
return
user
.
save
().
then
(
function
()
{
self
.
User
.
create
({
username
:
'new user'
}).
success
(
function
()
{
return
self
.
User
.
create
({
username
:
'new user'
}).
then
(
function
()
{
self
.
User
.
findAll
({
return
self
.
User
.
findAll
({
where
:
[
'createdAt > ?'
,
new
Date
(
2012
,
1
,
1
)]
where
:
[
'createdAt > ?'
,
new
Date
(
2012
,
1
,
1
)]
}).
success
(
function
(
users
)
{
}).
then
(
function
(
users
)
{
expect
(
users
).
to
.
have
.
length
(
1
);
expect
(
users
).
to
.
have
.
length
(
1
);
done
();
});
});
});
});
});
});
...
...
test/integration/model/create.test.js
View file @
3568ced
...
@@ -762,7 +762,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -762,7 +762,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
myvals
:
[
1
,
2
,
3
,
4
],
mystr
:
[
'One'
,
'Two'
,
'Three'
,
'Four'
]}).
on
(
'success'
,
function
(
user
)
{
User
.
create
({
myvals
:
[
1
,
2
,
3
,
4
],
mystr
:
[
'One'
,
'Two'
,
'Three'
,
'Four'
]}).
then
(
function
(
user
)
{
user
.
myvals
=
[];
user
.
myvals
=
[];
user
.
mystr
=
[];
user
.
mystr
=
[];
user
.
save
().
on
(
'sql'
,
function
(
sql
)
{
user
.
save
().
on
(
'sql'
,
function
(
sql
)
{
...
@@ -879,7 +879,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -879,7 +879,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
big
:
'9223372036854775807'
}).
on
(
'success'
,
function
(
user
)
{
User
.
create
({
big
:
'9223372036854775807'
}).
then
(
function
(
user
)
{
expect
(
user
.
big
).
to
.
be
.
equal
(
'9223372036854775807'
);
expect
(
user
.
big
).
to
.
be
.
equal
(
'9223372036854775807'
);
done
();
done
();
});
});
...
@@ -892,10 +892,10 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -892,10 +892,10 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
User
.
create
({}).
then
(
function
(
user
)
{
expect
(
user
.
userid
).
to
.
equal
(
1
);
expect
(
user
.
userid
).
to
.
equal
(
1
);
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
User
.
create
({}).
then
(
function
(
user
)
{
expect
(
user
.
userid
).
to
.
equal
(
2
);
expect
(
user
.
userid
).
to
.
equal
(
2
);
done
();
done
();
});
});
...
...
test/integration/model/findAll.test.js
View file @
3568ced
...
@@ -1251,7 +1251,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -1251,7 +1251,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
it
(
'finds all entries'
,
function
(
done
)
{
it
(
'finds all entries'
,
function
(
done
)
{
this
.
User
.
all
().
on
(
'success'
,
function
(
users
)
{
this
.
User
.
all
().
then
(
function
(
users
)
{
expect
(
users
.
length
).
to
.
equal
(
2
);
expect
(
users
.
length
).
to
.
equal
(
2
);
done
();
done
();
});
});
...
@@ -1535,7 +1535,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -1535,7 +1535,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
}
it
(
'should return all users'
,
function
(
done
)
{
it
(
'should return all users'
,
function
(
done
)
{
this
.
User
.
all
().
on
(
'success'
,
function
(
users
)
{
this
.
User
.
all
().
then
(
function
(
users
)
{
expect
(
users
.
length
).
to
.
equal
(
2
);
expect
(
users
.
length
).
to
.
equal
(
2
);
done
();
done
();
});
});
...
...
test/integration/promise.test.js
View file @
3568ced
...
@@ -383,7 +383,7 @@ describe(Support.getTestDialectTeaser('Promise'), function() {
...
@@ -383,7 +383,7 @@ describe(Support.getTestDialectTeaser('Promise'), function() {
resolve
(
'yoohoo'
);
resolve
(
'yoohoo'
);
});
});
promise
.
on
(
'success'
,
spy
);
promise
.
then
(
spy
);
promise
.
then
(
function
()
{
promise
.
then
(
function
()
{
expect
(
spy
.
calledOnce
).
to
.
be
.
true
;
expect
(
spy
.
calledOnce
).
to
.
be
.
true
;
expect
(
spy
.
firstCall
.
args
).
to
.
deep
.
equal
([
'yoohoo'
]);
expect
(
spy
.
firstCall
.
args
).
to
.
deep
.
equal
([
'yoohoo'
]);
...
...
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