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 3ac912bc
authored
Oct 06, 2012
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some more tests
1 parent
2e84bdda
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
26 deletions
spec/associations/mixin.spec.js
spec/dao-factory.spec.js
spec/associations/mixin.spec.js
0 → 100644
View file @
3ac912b
if
(
typeof
require
===
'function'
)
{
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
Sequelize
=
require
(
'../../index'
)
}
buster
.
spec
.
expose
()
describe
(
'Mixin'
,
function
()
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
beforeComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
}.
bind
(
this
),
onComplete
:
done
})
})
describe
(
'getAssociation'
,
function
()
{
it
(
'returns the respective part of the association for 1:1 associations'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{})
User
.
hasOne
(
Task
)
Task
.
belongsTo
(
User
)
expect
(
User
.
getAssociation
(
Task
).
target
).
toEqual
(
Task
)
})
})
})
spec/dao-factory.spec.js
View file @
3ac912b
...
@@ -362,35 +362,91 @@ dialects.forEach(function(dialect) {
...
@@ -362,35 +362,91 @@ dialects.forEach(function(dialect) {
if
(
dialect
===
'mysql'
)
{
if
(
dialect
===
'mysql'
)
{
it
(
'fetches associated objects for 1:1 associations'
,
function
(
done
)
{
describe
(
'association fetching'
,
function
()
{
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
before
(
function
()
{
title
:
Sequelize
.
STRING
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
})
title
:
Sequelize
.
STRING
})
this
.
User
=
this
.
sequelize
.
define
(
'UserWithName'
,
{
name
:
Sequelize
.
STRING
})
})
it
(
'fetches associated objects for 1:1 associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasOne
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
user
.
setTask
(
task
).
success
(
function
()
{
this
.
User
.
find
({
where
:
{
'UserWithNames.id'
:
1
},
include
:
[
'Task'
]
}).
success
(
function
(
user
)
{
expect
(
user
.
task
).
toBeDefined
()
expect
(
user
.
task
.
id
).
toEqual
(
task
.
id
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
it
(
'fetches associated objects for 1:1 associations (2nd direction)'
,
function
(
done
)
{
this
.
User
.
hasOne
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
user
.
setTask
(
task
).
success
(
function
()
{
this
.
Task
.
find
({
where
:
{
'Tasks.id'
:
1
},
include
:
[
'UserWithName'
]
}).
success
(
function
(
task
)
{
expect
(
task
.
userWithName
).
toBeDefined
()
expect
(
task
.
userWithName
.
id
).
toEqual
(
user
.
id
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
it
(
'//fetches associated objects for 1:N associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
User
.
find
({
where
:
{
'UserWithNames.id'
:
1
},
include
:
[
'Task'
]
}).
success
(
function
(
user
)
{
expect
(
user
.
tasks
).
toBeDefined
()
expect
(
user
.
tasks
.
map
(
function
(
t
)
{
return
t
.
id
})
).
toEqual
(
[
task1
.
id
,
task2
.
id
]
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
var
User
=
this
.
sequelize
.
define
(
'UserWithName'
,
{
name
:
Sequelize
.
STRING
})
})
User
.
hasOne
(
Task
)
Task
.
belongsTo
(
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
user
.
setTask
(
task
).
success
(
function
()
{
User
.
find
({
where
:
{
'UserWithNames.id'
:
1
},
include
:
[
'Task'
]
}).
success
(
function
(
user
)
{
expect
(
user
.
task
).
toBeDefined
()
expect
(
user
.
task
.
id
).
toEqual
(
task
.
id
)
done
()
})
})
//- setTask
})
//- Task.create
})
//- User.create
})
//- sequelize.sync
})
}
}
})
})
...
...
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