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 30d327d4
authored
Apr 01, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests for find and findall
1 parent
1da66da2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
11 deletions
test/Model/find-findAll-all.js
test/Model/find-findAll-all.js
View file @
30d327d
...
@@ -3,20 +3,23 @@ var assert = require("assert")
...
@@ -3,20 +3,23 @@ var assert = require("assert")
,
Sequelize
=
require
(
"./../../index"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
var
initUsers
=
function
(
callback
)
{
var
initUsers
=
function
(
num
,
callback
)
{
var
User
=
sequelize
.
define
(
'User'
+
parseInt
(
Math
.
random
()
*
99999999
),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
var
User
=
sequelize
.
define
(
'User'
+
parseInt
(
Math
.
random
()
*
99999999
),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
var
createUser
=
function
()
{
User
.
create
({
name
:
'foo'
,
bio
:
'foobar'
}).
on
(
'success'
,
function
()
{
User
.
create
({
name
:
'user'
+
num
,
bio
:
'foobar'
}).
on
(
'success'
,
function
(
user
){
User
.
create
({
name
:
'bar'
,
bio
:
'foobar'
}).
on
(
'success'
,
function
(
user
)
{
if
(
--
num
)
createUser
()
callback
(
user
,
User
)
else
callback
(
user
,
User
)
})
})
})
}
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
createUser
()
})
})
}
}
module
.
exports
=
{
module
.
exports
=
{
'all should return all created models'
:
function
(
exit
)
{
'all should return all created models'
:
function
(
exit
)
{
initUsers
(
function
(
_
,
User
)
{
initUsers
(
2
,
function
(
_
,
User
)
{
User
.
all
.
on
(
'success'
,
function
(
users
)
{
User
.
all
.
on
(
'success'
,
function
(
users
)
{
assert
.
eql
(
users
.
length
,
2
)
assert
.
eql
(
users
.
length
,
2
)
exit
()
exit
()
...
@@ -24,7 +27,7 @@ module.exports = {
...
@@ -24,7 +27,7 @@ module.exports = {
})
})
},
},
'find should return a single model'
:
function
(
exit
)
{
'find should return a single model'
:
function
(
exit
)
{
initUsers
(
function
(
lastInsertedUser
,
User
)
{
initUsers
(
2
,
function
(
lastInsertedUser
,
User
)
{
User
.
find
(
lastInsertedUser
.
id
).
on
(
'success'
,
function
(
user
)
{
User
.
find
(
lastInsertedUser
.
id
).
on
(
'success'
,
function
(
user
)
{
assert
.
eql
(
user
.
id
,
lastInsertedUser
.
id
)
assert
.
eql
(
user
.
id
,
lastInsertedUser
.
id
)
exit
()
exit
()
...
@@ -32,9 +35,60 @@ module.exports = {
...
@@ -32,9 +35,60 @@ module.exports = {
})
})
},
},
'find a specific user'
:
function
(
exit
)
{
'find a specific user'
:
function
(
exit
)
{
initUsers
(
function
(
u
,
User
)
{
initUsers
(
2
,
function
(
_
,
User
)
{
User
.
find
({
name
:
'foo'
}).
on
(
'success'
,
function
(
user
)
{
var
username
=
'user1'
assert
.
eql
(
user
.
name
,
'foo'
)
User
.
find
({
where
:
{
name
:
username
}}).
on
(
'success'
,
function
(
user
)
{
assert
.
eql
(
user
.
name
,
username
)
exit
()
})
})
},
'should find no user with invalid conditions'
:
function
(
exit
)
{
initUsers
(
2
,
function
(
_
,
User
)
{
User
.
find
({
where
:
{
name
:
'foo'
}}).
on
(
'success'
,
function
(
user
)
{
assert
.
eql
(
user
,
null
)
exit
()
})
})
},
'find should ignore passed limit'
:
function
(
exit
)
{
initUsers
(
2
,
function
(
_
,
User
)
{
User
.
find
({
limit
:
10
}).
on
(
'success'
,
function
(
user
)
{
// it returns an object instead of an array
assert
.
eql
(
user
.
hasOwnProperty
(
'name'
),
true
)
exit
()
})
})
},
'findAll should find all records'
:
function
(
exit
)
{
initUsers
(
2
,
function
(
_
,
User
)
{
User
.
findAll
().
on
(
'success'
,
function
(
users
)
{
assert
.
eql
(
users
.
length
,
2
)
exit
()
})
})
},
'findAll should return the correct elements for passed conditions'
:
function
(
exit
)
{
initUsers
(
2
,
function
(
lastUser
,
User
)
{
User
.
findAll
({
where
:
"id != "
+
lastUser
.
id
}).
on
(
'success'
,
function
(
users
)
{
assert
.
eql
(
users
.
length
,
1
)
exit
()
})
})
},
'findAll should return the correct order when order is passed'
:
function
(
exit
)
{
initUsers
(
2
,
function
(
lastUser
,
User
)
{
User
.
findAll
({
order
:
"id DESC"
}).
on
(
'success'
,
function
(
users
)
{
assert
.
eql
(
users
[
0
].
id
>
users
[
1
].
id
,
true
)
exit
()
})
})
},
'findAll should handle offset and limit correctly'
:
function
(
exit
)
{
initUsers
(
10
,
function
(
_
,
User
)
{
User
.
findAll
({
limit
:
2
,
offset
:
2
}).
on
(
'success'
,
function
(
users
)
{
assert
.
eql
(
users
.
length
,
2
)
assert
.
eql
(
users
[
0
].
id
,
3
)
exit
()
exit
()
})
})
})
})
...
...
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