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 1cd32292
authored
Sep 30, 2012
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved specs to buster
1 parent
bb8033d9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
87 deletions
spec-jasmine/dao-factory.spec.js
spec/dao-factory.spec.js
spec-jasmine/dao-factory.spec.js
View file @
1cd3229
...
...
@@ -131,93 +131,6 @@ describe('DAOFactory', function() {
})
})
describe
(
'find'
,
function
()
{
var
users
=
[]
beforeEach
(
function
()
{
Helpers
.
Factories
.
User
({
name
:
'user'
,
bio
:
'foobar'
},
function
(
_users
)
{
users
=
_users
},
2
)
})
it
(
"should make aliased attributes available"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
find
({
where
:
'id = 1'
,
attributes
:
[
'id'
,
[
'name'
,
'username'
]]
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'user'
)
done
()
})
})
})
it
(
'returns a single dao'
,
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
(
'allows sql logging'
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
find
({
where
:
{
name
:
'foo'
}
})
.
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
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
()
})
})
})
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
=
[]
...
...
spec/dao-factory.spec.js
View file @
1cd3229
...
...
@@ -276,5 +276,113 @@ dialects.forEach(function(dialect) {
})
})
})
describe
(
'find'
,
function
find
()
{
before
(
function
(
done
)
{
this
.
User
.
create
({
username
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
user
=
user
done
()
}.
bind
(
this
))
})
it
(
'returns a single dao'
,
function
(
done
)
{
this
.
User
.
find
(
this
.
user
.
id
).
success
(
function
(
user
)
{
expect
(
Array
.
isArray
(
user
)).
toBeFalsy
()
expect
(
user
.
id
).
toEqual
(
this
.
user
.
id
)
expect
(
user
.
id
).
toEqual
(
1
)
done
()
}.
bind
(
this
))
})
it
(
"should make aliased attributes available"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
id
:
1
},
attributes
:
[
'id'
,
[
'username'
,
'name'
]]
}).
success
(
function
(
user
)
{
expect
(
user
.
name
).
toEqual
(
'barfooz'
)
done
()
})
})
it
(
'finds a specific user via where option'
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'barfooz'
}
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'barfooz'
)
done
()
})
})
it
(
"doesn't find a user if conditions are not matching"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'foo'
}
}).
success
(
function
(
user
)
{
expect
(
user
).
toBeNull
()
done
()
})
})
it
(
'allows sql logging'
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'foo'
}
})
.
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
done
()
})
})
it
(
'ignores passed limit option'
,
function
(
done
)
{
this
.
User
.
find
({
limit
:
10
}).
success
(
function
(
user
)
{
// it returns an object instead of an array
expect
(
Array
.
isArray
(
user
)).
toBeFalsy
()
expect
(
user
.
hasOwnProperty
(
'username'
)).
toBeTruthy
()
done
()
})
})
it
(
'finds entries via primary keys'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithPrimaryKey'
,
{
identifier
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
},
name
:
Sequelize
.
STRING
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
identifier
:
'an identifier'
,
name
:
'John'
}).
success
(
function
(
u
)
{
expect
(
u
.
id
).
not
.
toBeDefined
()
User
.
find
(
'an identifier'
).
success
(
function
(
u2
)
{
expect
(
u2
.
identifier
).
toEqual
(
'an identifier'
)
expect
(
u2
.
name
).
toEqual
(
'John'
)
done
()
})
})
})
})
it
(
'=>fetches associated objects for 1:1 associations'
,
function
(
done
)
{
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
this
.
User
.
hasOne
(
Task
)
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
this
.
user
.
setTask
(
task
).
success
(
function
()
{
this
.
User
.
find
({
where
:
{
id
:
1
},
include
:
'Task'
}).
success
(
function
(
user
)
{
expect
(
user
.
task
).
toBeDefined
()
expect
(
user
.
task
).
toEqual
(
task
)
done
()
}.
bind
(
this
))
}.
bind
(
this
))
}.
bind
(
this
))
}.
bind
(
this
))
})
})
})
})
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