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 f651219f
authored
Dec 15, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
find specs
1 parent
9215d003
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
43 deletions
spec/model-factory.spec.js
test/Model/find-findAll-all.js
spec/model-factory.spec.js
View file @
f651219
...
...
@@ -201,8 +201,12 @@ describe('ModelFactory', function() {
})
describe
(
'find'
,
function
()
{
var
users
=
[]
beforeEach
(
function
()
{
Helpers
.
Factories
.
User
({
name
:
'user'
,
bio
:
'foobar'
},
null
,
2
)
Helpers
.
Factories
.
User
({
name
:
'user'
,
bio
:
'foobar'
},
function
(
_users
)
{
users
=
_users
},
2
)
})
it
(
"should make aliased attributes available"
,
function
()
{
...
...
@@ -213,6 +217,45 @@ describe('ModelFactory', function() {
})
})
})
it
(
'returns a single model'
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
find
(
users
[
0
].
id
).
success
(
function
(
user
)
{
expect
(
Array
.
isArray
(
user
)).
toBeFalsy
()
expect
(
user
.
id
).
toEqual
(
users
[
0
].
id
)
done
()
})
})
})
it
(
'finds a specific user via where option'
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
find
({
where
:
{
name
:
'user'
}}).
success
(
function
(
user
)
{
expect
(
user
.
name
).
toEqual
(
'user'
)
done
()
})
})
})
it
(
"doesn't find a user if conditions are not matching"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
find
({
where
:
{
name
:
'foo'
}
}).
success
(
function
(
user
)
{
expect
(
user
).
toBeNull
()
done
()
})
})
})
it
(
'ignores passed limit option'
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
find
({
limit
:
10
}).
success
(
function
(
user
)
{
// it returns an object instead of an array
expect
(
Array
.
isArray
(
user
)).
toBeFalsy
()
expect
(
user
.
hasOwnProperty
(
'name'
)).
toBeTruthy
()
done
()
})
})
})
})
describe
(
'all'
,
function
()
{
...
...
test/Model/find-findAll-all.js
View file @
f651219
...
...
@@ -18,48 +18,6 @@ var initUsers = function(num, callback) {
}
module
.
exports
=
{
'all should return all created models'
:
function
(
exit
)
{
initUsers
(
2
,
function
(
_
,
User
)
{
User
.
all
().
on
(
'success'
,
function
(
users
)
{
assert
.
eql
(
users
.
length
,
2
)
exit
(
function
(){})
})
})
},
'find should return a single model'
:
function
(
exit
)
{
initUsers
(
2
,
function
(
lastInsertedUser
,
User
)
{
User
.
find
(
lastInsertedUser
.
id
).
on
(
'success'
,
function
(
user
)
{
assert
.
eql
(
user
.
id
,
lastInsertedUser
.
id
)
exit
(
function
(){})
})
})
},
'find a specific user'
:
function
(
exit
)
{
initUsers
(
2
,
function
(
_
,
User
)
{
var
username
=
'user1'
User
.
find
({
where
:
{
name
:
username
}}).
on
(
'success'
,
function
(
user
)
{
assert
.
eql
(
user
.
name
,
username
)
exit
(
function
(){})
})
})
},
'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
(
function
(){})
})
})
},
'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
(
function
(){})
})
})
},
'find should find records by primaryKeys'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
identifier
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
},
...
...
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