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 4ecc546d
authored
Oct 12, 2012
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exec association specs for every dialect
1 parent
7968f093
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
261 additions
and
250 deletions
spec/associations/belongs-to.spec.js
spec/associations/has-many.spec.js
spec/associations/has-one.spec.js
spec/associations/belongs-to.spec.js
View file @
4ecc546
...
@@ -2,42 +2,45 @@ if (typeof require === 'function') {
...
@@ -2,42 +2,45 @@ if (typeof require === 'function') {
const
buster
=
require
(
"buster"
)
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
Sequelize
=
require
(
'../../index'
)
,
Sequelize
=
require
(
'../../index'
)
,
dialects
=
Helpers
.
getSupportedDialects
()
}
}
buster
.
spec
.
expose
()
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
500
buster
.
testRunner
.
timeout
=
500
describe
(
'BelongsTo'
,
function
()
{
dialects
.
forEach
(
function
(
dialect
)
{
before
(
function
(
done
)
{
describe
(
'BelongsTo@'
+
dialect
,
function
()
{
Helpers
.
initTests
({
before
(
function
(
done
)
{
beforeComplete
:
function
(
sequelize
)
{
Helpers
.
initTests
({
this
.
sequelize
=
sequelize
beforeComplete
:
function
(
sequelize
)
{
}.
bind
(
this
),
this
.
sequelize
=
sequelize
onComplete
:
done
}.
bind
(
this
),
onComplete
:
done
})
})
})
})
describe
(
'setAssociation'
,
function
()
{
describe
(
'setAssociation'
,
function
()
{
it
(
'clears the association if null is passed'
,
function
(
done
)
{
it
(
'clears the association if null is passed'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
Task
.
belongsTo
(
User
)
Task
.
belongsTo
(
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUser
(
user
).
success
(
function
()
{
task
.
setUser
(
user
).
success
(
function
()
{
task
.
getUser
().
success
(
function
(
user
)
{
task
.
getUser
().
success
(
function
(
user
)
{
expect
(
user
).
not
.
toEqual
(
null
)
expect
(
user
).
not
.
toEqual
(
null
)
task
.
setUser
(
null
).
success
(
function
()
{
task
.
setUser
(
null
).
success
(
function
()
{
task
.
getUser
().
success
(
function
(
user
)
{
task
.
getUser
().
success
(
function
(
user
)
{
expect
(
user
).
toEqual
(
null
)
expect
(
user
).
toEqual
(
null
)
done
()
done
()
})
})
})
})
})
})
})
})
})
})
})
...
...
spec/associations/has-many.spec.js
View file @
4ecc546
...
@@ -2,131 +2,163 @@ if (typeof require === 'function') {
...
@@ -2,131 +2,163 @@ if (typeof require === 'function') {
const
buster
=
require
(
"buster"
)
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
Sequelize
=
require
(
'../../index'
)
,
Sequelize
=
require
(
'../../index'
)
,
dialects
=
Helpers
.
getSupportedDialects
()
}
}
buster
.
spec
.
expose
()
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
500
buster
.
testRunner
.
timeout
=
500
describe
(
'HasMany'
,
function
()
{
dialects
.
forEach
(
function
(
dialect
)
{
before
(
function
(
done
)
{
describe
(
'HasMany@'
+
dialect
,
function
()
{
var
self
=
this
before
(
function
(
done
)
{
var
self
=
this
Helpers
.
initTests
({
Helpers
.
initTests
({
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
dialect
:
dialect
,
onComplete
:
done
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
onComplete
:
done
})
})
})
})
describe
(
'(1:N)'
,
function
()
{
describe
(
'hasSingle'
,
function
()
{
before
(
function
(
done
)
{
this
.
Article
=
this
.
sequelize
.
define
(
'Article'
,
{
'title'
:
Sequelize
.
STRING
})
this
.
Label
=
this
.
sequelize
.
define
(
'Label'
,
{
'text'
:
Sequelize
.
STRING
})
this
.
Article
.
hasMany
(
this
.
Label
)
describe
(
'(1:N)'
,
function
()
{
describe
(
'hasSingle'
,
function
()
{
before
(
function
(
done
)
{
this
.
Article
=
this
.
sequelize
.
define
(
'Article'
,
{
'title'
:
Sequelize
.
STRING
})
this
.
Label
=
this
.
sequelize
.
define
(
'Label'
,
{
'text'
:
Sequelize
.
STRING
})
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
done
)
this
.
Article
.
hasMany
(
this
.
Label
)
})
it
(
'does not have any labels assigned to it initially'
,
function
(
done
)
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
done
)
var
self
=
this
})
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
it
(
'does not have any labels assigned to it initially'
,
function
(
done
)
{
this
.
Article
.
create
({
title
:
'Article'
}),
var
self
=
this
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
])
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
article
.
hasLabel
(
label1
),
this
.
Article
.
create
({
title
:
'Article'
}),
article
.
hasLabel
(
label2
)
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
])
])
chainer
.
run
().
success
(
function
(
_
,
hasLabel1
,
hasLabel2
)
{
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
expect
(
hasLabel1
).
toBeFalse
()
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
expect
(
hasLabel2
).
toBeFalse
()
article
.
hasLabel
(
label1
),
done
()
article
.
hasLabel
(
label2
)
])
chainer
.
run
().
success
(
function
(
_
,
hasLabel1
,
hasLabel2
)
{
expect
(
hasLabel1
).
toBeFalse
()
expect
(
hasLabel2
).
toBeFalse
()
done
()
})
})
})
})
})
})
it
(
'answers true if the label has been assigned'
,
function
(
done
)
{
it
(
'answers true if the label has been assigned'
,
function
(
done
)
{
var
self
=
this
var
self
=
this
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
])
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
[
article
,
'addLabel'
,
[
label1
]]
,
this
.
Article
.
create
({
title
:
'Article'
})
,
[
article
,
'hasLabel'
,
[
label1
]]
,
this
.
Label
.
create
({
text
:
'Awesomeness'
})
,
[
article
,
'hasLabel'
,
[
label2
]]
this
.
Label
.
create
({
text
:
'Epicness'
})
])
])
chainer
.
runSerially
().
success
(
function
(
_
,
label1
,
hasLabel1
,
hasLabel2
)
{
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
expect
(
hasLabel1
).
toBeTrue
()
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
expect
(
hasLabel2
).
toBeFalse
()
[
article
,
'addLabel'
,
[
label1
]],
done
()
[
article
,
'hasLabel'
,
[
label1
]],
[
article
,
'hasLabel'
,
[
label2
]]
])
chainer
.
runSerially
().
success
(
function
(
_
,
label1
,
hasLabel1
,
hasLabel2
)
{
expect
(
hasLabel1
).
toBeTrue
()
expect
(
hasLabel2
).
toBeFalse
()
done
()
})
})
})
})
})
})
})
})
describe
(
'hasAll'
,
function
()
{
describe
(
'hasAll'
,
function
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
this
.
Article
=
this
.
sequelize
.
define
(
'Article'
,
{
'title'
:
Sequelize
.
STRING
})
this
.
Article
=
this
.
sequelize
.
define
(
'Article'
,
{
'title'
:
Sequelize
.
STRING
})
this
.
Label
=
this
.
sequelize
.
define
(
'Label'
,
{
'text'
:
Sequelize
.
STRING
})
this
.
Label
=
this
.
sequelize
.
define
(
'Label'
,
{
'text'
:
Sequelize
.
STRING
})
this
.
Article
.
hasMany
(
this
.
Label
)
this
.
Article
.
hasMany
(
this
.
Label
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
done
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
done
)
})
})
it
(
'answers false if only some labels have been assigned'
,
function
(
done
)
{
it
(
'answers false if only some labels have been assigned'
,
function
(
done
)
{
var
self
=
this
var
self
=
this
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
this
.
Label
.
create
({
text
:
'Epicness'
})
])
])
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
article
.
addLabel
(
label1
).
success
(
function
()
{
article
.
addLabel
(
label1
).
success
(
function
()
{
article
.
hasLabels
([
label1
,
label2
]).
success
(
function
(
result
)
{
article
.
hasLabels
([
label1
,
label2
]).
success
(
function
(
result
)
{
expect
(
result
).
toBeFalse
()
expect
(
result
).
toBeFalse
()
done
()
done
()
})
})
})
})
it
(
'answers true if all label have been assigned'
,
function
(
done
)
{
var
self
=
this
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
])
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
article
.
setLabels
([
label1
,
label2
]).
success
(
function
()
{
article
.
hasLabels
([
label1
,
label2
]).
success
(
function
(
result
)
{
expect
(
result
).
toBeTrue
()
done
()
})
})
})
})
})
})
})
})
})
it
(
'answers true if all label have been assigned'
,
function
(
done
)
{
describe
(
'setAssociations'
,
function
()
{
var
self
=
this
it
(
"clears associations when passing null to the set-method"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
Task
.
hasMany
(
User
)
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
])
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
article
.
setLabels
([
label1
,
label2
]).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
article
.
hasLabels
([
label1
,
label2
]).
success
(
function
(
result
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
expect
(
result
).
toBeTrue
()
task
.
setUsers
([
user
]).
success
(
function
()
{
done
()
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
1
)
task
.
setUsers
(
null
).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
0
)
done
()
})
})
})
})
})
})
})
})
})
})
})
})
})
})
describe
(
'setAssociations'
,
function
()
{
it
(
"clears associations when passing null to the set-method with omitNull set to true"
,
function
(
done
)
{
it
(
"clears associations when passing null to the set-method"
,
function
(
done
)
{
this
.
sequelize
.
options
.
omitNull
=
true
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
...
@@ -151,166 +183,138 @@ describe('HasMany', function() {
...
@@ -151,166 +183,138 @@ describe('HasMany', function() {
})
})
})
})
})
})
})
it
(
"clears associations when passing null to the set-method with omitNull set to true"
,
function
(
done
)
{
describe
(
"getting assocations with options"
,
function
()
{
this
.
sequelize
.
options
.
omitNull
=
true
before
(
function
(
done
)
{
var
self
=
this
;
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
,
active
:
Sequelize
.
BOOLEAN
})
Task
.
hasMany
(
User
)
this
.
User
.
hasMany
(
self
.
Task
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
self
.
User
.
create
({
username
:
'John'
}),
task
.
setUsers
([
user
]).
success
(
function
()
{
self
.
Task
.
create
({
title
:
'Get rich'
,
active
:
true
}),
task
.
getUsers
().
success
(
function
(
_users
)
{
self
.
Task
.
create
({
title
:
'Die trying'
,
active
:
false
})
expect
(
_users
.
length
).
toEqual
(
1
)
]
)
task
.
setUsers
(
null
).
success
(
function
()
{
chainer
.
run
().
success
(
function
(
results
,
john
,
task1
,
task2
)
{
task
.
getUsers
().
success
(
function
(
_users
)
{
john
.
setTasks
([
task1
,
task2
]).
success
(
done
)
expect
(
_users
.
length
).
toEqual
(
0
)
done
()
})
})
})
})
})
})
})
})
})
})
})
describe
(
"getting assocations with options"
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
;
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
,
active
:
Sequelize
.
BOOLEAN
})
this
.
User
.
hasMany
(
self
.
Task
)
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
()
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
self
.
User
.
create
({
username
:
'John'
}),
self
.
Task
.
create
({
title
:
'Get rich'
,
active
:
true
}),
self
.
Task
.
create
({
title
:
'Die trying'
,
active
:
false
})
])
chainer
.
run
().
success
(
function
(
results
,
john
,
task1
,
task2
)
{
john
.
setTasks
([
task1
,
task2
]).
success
(
done
)
})
})
})
it
(
"gets all associated objects when no options are passed"
,
function
(
done
)
{
it
(
"gets all associated objects when no options are passed"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
().
success
(
function
(
tasks
)
{
john
.
getTasks
().
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
2
)
expect
(
tasks
.
length
).
toEqual
(
2
)
done
();
done
();
})
})
})
})
})
})
it
(
"only get objects that fullfil the options"
,
function
(
done
)
{
it
(
"only get objects that fullfil the options"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
},
limit
:
10
,
order
:
'ID DESC'
}).
success
(
function
(
tasks
)
{
john
.
getTasks
({
where
:
{
active
:
true
},
limit
:
10
,
order
:
'ID DESC'
}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
expect
(
tasks
.
length
).
toEqual
(
1
)
done
();
done
();
})
})
})
})
})
})
})
})
})
})
describe
(
'(N:M)'
,
function
()
{
describe
(
'(N:M)'
,
function
()
{
describe
(
"getting assocations with options"
,
function
()
{
describe
(
"getting assocations with options"
,
function
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
var
self
=
this
;
var
self
=
this
;
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
,
active
:
Sequelize
.
BOOLEAN
})
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
,
active
:
Sequelize
.
BOOLEAN
})
self
.
User
.
hasMany
(
self
.
Task
)
self
.
User
.
hasMany
(
self
.
Task
)
self
.
Task
.
hasMany
(
self
.
User
)
self
.
Task
.
hasMany
(
self
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
()
{
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
()
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
self
.
User
.
create
({
username
:
'John'
}),
self
.
User
.
create
({
username
:
'John'
}),
self
.
Task
.
create
({
title
:
'Get rich'
,
active
:
true
}),
self
.
Task
.
create
({
title
:
'Get rich'
,
active
:
true
}),
self
.
Task
.
create
({
title
:
'Die trying'
,
active
:
false
})
self
.
Task
.
create
({
title
:
'Die trying'
,
active
:
false
})
])
])
chainer
.
run
().
success
(
function
(
results
,
john
,
task1
,
task2
)
{
chainer
.
run
().
success
(
function
(
results
,
john
,
task1
,
task2
)
{
john
.
setTasks
([
task1
,
task2
]).
success
(
done
)
john
.
setTasks
([
task1
,
task2
]).
success
(
done
)
})
})
})
})
})
})
it
(
"gets all associated objects when no options are passed"
,
function
(
done
)
{
it
(
"gets all associated objects when no options are passed"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
().
success
(
function
(
tasks
)
{
john
.
getTasks
().
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
2
)
expect
(
tasks
.
length
).
toEqual
(
2
)
done
();
done
();
})
})
})
})
})
})
it
(
"only get objects that fullfil the options"
,
function
(
done
)
{
it
(
"only get objects that fullfil the options"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
}}).
success
(
function
(
tasks
)
{
john
.
getTasks
({
where
:
{
active
:
true
}}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
expect
(
tasks
.
length
).
toEqual
(
1
)
done
();
done
();
})
})
})
})
})
})
})
})
it
(
"removes the reference id, which was added in the first place"
,
function
()
{
it
(
"removes the reference id, which was added in the first place"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
)
User
.
hasMany
(
Task
)
expect
(
Task
.
attributes
.
UserId
).
toBeDefined
()
expect
(
Task
.
attributes
.
UserId
).
toBeDefined
()
Task
.
hasMany
(
User
)
Task
.
hasMany
(
User
)
expect
(
Task
.
attributes
.
UserId
).
not
.
toBeDefined
()
expect
(
Task
.
attributes
.
UserId
).
not
.
toBeDefined
()
})
})
it
(
"adds three items to the query chainer when calling sync"
,
function
()
{
it
(
"adds three items to the query chainer when calling sync"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
)
User
.
hasMany
(
Task
)
Task
.
hasMany
(
User
)
Task
.
hasMany
(
User
)
var
add
=
this
.
spy
()
var
add
=
this
.
spy
()
this
.
stub
(
Sequelize
.
Utils
,
'QueryChainer'
).
returns
({
add
:
add
,
run
:
function
(){}
})
this
.
stub
(
Sequelize
.
Utils
,
'QueryChainer'
).
returns
({
add
:
add
,
run
:
function
(){}
})
this
.
sequelize
.
sync
({
force
:
true
})
this
.
sequelize
.
sync
({
force
:
true
})
expect
(
add
).
toHaveBeenCalledThrice
()
expect
(
add
).
toHaveBeenCalledThrice
()
})
})
describe
(
'setAssociations'
,
function
()
{
describe
(
'setAssociations'
,
function
()
{
it
(
"clears associations when passing null to the set-method"
,
function
(
done
)
{
it
(
"clears associations when passing null to the set-method"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
)
User
.
hasMany
(
Task
)
Task
.
hasMany
(
User
)
Task
.
hasMany
(
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUsers
([
user
]).
success
(
function
()
{
task
.
setUsers
([
user
]).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
1
)
expect
(
_users
.
length
).
toEqual
(
1
)
task
.
setUsers
(
null
).
success
(
function
()
{
task
.
setUsers
(
null
).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
0
)
expect
(
_users
.
length
).
toEqual
(
0
)
done
()
done
()
})
})
})
})
})
})
})
...
...
spec/associations/has-one.spec.js
View file @
4ecc546
...
@@ -2,42 +2,46 @@ if (typeof require === 'function') {
...
@@ -2,42 +2,46 @@ if (typeof require === 'function') {
const
buster
=
require
(
"buster"
)
const
buster
=
require
(
"buster"
)
,
Sequelize
=
require
(
"../../index"
)
,
Sequelize
=
require
(
"../../index"
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
dialects
=
Helpers
.
getSupportedDialects
()
}
}
buster
.
spec
.
expose
()
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
500
buster
.
testRunner
.
timeout
=
500
describe
(
'HasOne'
,
function
()
{
dialects
.
forEach
(
function
(
dialect
)
{
before
(
function
(
done
)
{
describe
(
'HasOne@'
+
dialect
,
function
()
{
var
self
=
this
before
(
function
(
done
)
{
var
self
=
this
Helpers
.
initTests
({
Helpers
.
initTests
({
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
dialect
:
dialect
,
onComplete
:
done
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
onComplete
:
done
})
})
})
})
describe
(
'setAssociation'
,
function
()
{
it
(
'clears the association if null is passed'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
User
.
hasOne
(
Task
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
describe
(
'setAssociation'
,
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
it
(
'clears the association if null is passed'
,
function
(
done
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
user
.
setTask
(
task
).
success
(
function
()
{
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
user
.
getTask
().
success
(
function
(
task
)
{
expect
(
task
).
not
.
toEqual
(
null
)
User
.
hasOne
(
Task
)
user
.
setTask
(
null
).
success
(
function
()
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
user
.
getTask
().
success
(
function
(
task
)
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
expect
(
task
).
toEqual
(
null
)
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
done
()
user
.
setTask
(
task
).
success
(
function
()
{
user
.
getTask
().
success
(
function
(
task
)
{
expect
(
task
).
not
.
toEqual
(
null
)
user
.
setTask
(
null
).
success
(
function
()
{
user
.
getTask
().
success
(
function
(
task
)
{
expect
(
task
).
toEqual
(
null
)
done
()
})
})
})
})
})
})
})
})
})
})
})
...
...
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