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 0e554941
authored
Dec 18, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved specs
1 parent
f651219f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
79 deletions
spec/model-factory.spec.js
test/Model/find-findAll-all.js
spec/model-factory.spec.js
View file @
0e55494
...
@@ -256,6 +256,85 @@ describe('ModelFactory', function() {
...
@@ -256,6 +256,85 @@ describe('ModelFactory', function() {
})
})
})
})
})
})
it
(
'finds entries via primary keys'
,
function
()
{
setup
({
identifier
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
},
name
:
Sequelize
.
STRING
})
Helpers
.
async
(
function
(
done
)
{
User
.
create
({
identifier
:
'an identifier'
,
name
:
'John'
}).
success
(
function
(
u
)
{
expect
(
u
.
id
).
toBeUndefined
()
User
.
find
(
'an identifier'
).
success
(
function
(
u2
)
{
expect
(
u2
.
identifier
).
toEqual
(
'an identifier'
)
expect
(
u2
.
name
).
toEqual
(
'John'
)
done
()
})
})
})
})
})
describe
(
'findAll'
,
function
()
{
var
users
=
[]
beforeEach
(
function
()
{
Helpers
.
Factories
.
User
({
name
:
'user'
,
bio
:
'foobar'
},
function
(
_users
)
{
users
=
_users
},
2
)
})
it
(
"finds all entries"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
findAll
().
on
(
'success'
,
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
2
)
done
()
})
})
})
it
(
"finds all users matching the passed conditions"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
findAll
({
where
:
"id != "
+
users
[
1
].
id
}).
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
1
)
done
()
})
})
})
it
(
"can also handle array notation"
,
function
()
{
Helpers
.
async
(
function
(
done
){
User
.
findAll
({
where
:
[
'id = ?'
,
users
[
1
].
id
]}).
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
1
)
expect
(
_users
[
0
].
id
).
toEqual
(
users
[
1
].
id
)
done
()
})
})
})
it
(
"sorts the results"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
findAll
({
order
:
"id DESC"
}).
success
(
function
(
users
)
{
expect
(
users
[
0
].
id
).
toBeGreaterThan
(
users
[
1
].
id
)
done
()
})
})
})
it
(
"handles offset and limit"
,
function
()
{
setup
()
Helpers
.
Factories
.
User
({
name
:
'user'
,
bio
:
'foobar'
},
null
,
10
)
Helpers
.
async
(
function
(
done
)
{
User
.
findAll
({
limit
:
2
,
offset
:
2
}).
success
(
function
(
users
)
{
expect
(
users
.
length
).
toEqual
(
2
)
expect
(
users
[
0
].
id
).
toEqual
(
3
)
done
()
})
})
})
})
})
describe
(
'all'
,
function
()
{
describe
(
'all'
,
function
()
{
...
...
test/Model/find-findAll-all.js
deleted
100644 → 0
View file @
f651219
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}})
var
initUsers
=
function
(
num
,
callback
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
var
createUser
=
function
()
{
User
.
create
({
name
:
'user'
+
num
,
bio
:
'foobar'
}).
on
(
'success'
,
function
(
user
){
if
(
--
num
)
createUser
()
else
callback
(
user
,
User
)
})
}
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
createUser
()
})
}
module
.
exports
=
{
'find should find records by primaryKeys'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
identifier
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
},
name
:
Sequelize
.
STRING
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
identifier
:
'an identifier'
,
name
:
'John'
}).
on
(
'success'
,
function
(
u
)
{
assert
.
isUndefined
(
u
.
id
)
User
.
find
(
'an identifier'
).
on
(
'success'
,
function
(
u2
)
{
assert
.
eql
(
u
.
identifier
,
'an identifier'
)
assert
.
eql
(
u
.
name
,
'John'
)
exit
(
function
(){})
})
})
})
},
'findAll should find all records'
:
function
(
exit
)
{
initUsers
(
2
,
function
(
_
,
User
)
{
User
.
findAll
().
on
(
'success'
,
function
(
users
)
{
assert
.
eql
(
users
.
length
,
2
)
exit
(
function
(){})
})
})
},
'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
(
function
(){})
})
})
},
'findAll should work with array usage'
:
function
(
exit
)
{
initUsers
(
2
,
function
(
lastUser
,
User
)
{
User
.
findAll
({
where
:
[
'id = ?'
,
lastUser
.
id
]}).
on
(
'success'
,
function
(
users
)
{
assert
.
eql
(
users
.
length
,
1
)
assert
.
eql
(
users
[
0
].
id
,
lastUser
.
id
)
exit
(
function
(){})
})
})
},
'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
(
function
(){})
})
})
},
'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
(
function
(){})
})
})
}
}
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