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') {
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
Sequelize
=
require
(
'../../index'
)
,
dialects
=
Helpers
.
getSupportedDialects
()
}
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
500
describe
(
'BelongsTo'
,
function
()
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
beforeComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
}.
bind
(
this
),
onComplete
:
done
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
'BelongsTo@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
beforeComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
}.
bind
(
this
),
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
})
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
})
Task
.
belongsTo
(
User
)
Task
.
belongsTo
(
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUser
(
user
).
success
(
function
()
{
task
.
getUser
().
success
(
function
(
user
)
{
expect
(
user
).
not
.
toEqual
(
null
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUser
(
user
).
success
(
function
()
{
task
.
getUser
().
success
(
function
(
user
)
{
expect
(
user
).
not
.
toEqual
(
null
)
task
.
setUser
(
null
).
success
(
function
()
{
task
.
getUser
().
success
(
function
(
user
)
{
expect
(
user
).
toEqual
(
null
)
done
()
task
.
setUser
(
null
).
success
(
function
()
{
task
.
getUser
().
success
(
function
(
user
)
{
expect
(
user
).
toEqual
(
null
)
done
()
})
})
})
})
})
})
})
...
...
spec/associations/has-many.spec.js
View file @
4ecc546
...
...
@@ -2,131 +2,163 @@ if (typeof require === 'function') {
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
Sequelize
=
require
(
'../../index'
)
,
dialects
=
Helpers
.
getSupportedDialects
()
}
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
500
describe
(
'HasMany'
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
'HasMany@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
Helpers
.
initTests
({
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
onComplete
:
done
Helpers
.
initTests
({
dialect
:
dialect
,
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
)
{
var
self
=
this
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
done
)
})
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
])
it
(
'does not have any labels assigned to it initially'
,
function
(
done
)
{
var
self
=
this
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
article
.
hasLabel
(
label1
),
article
.
hasLabel
(
label2
)
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
])
chainer
.
run
().
success
(
function
(
_
,
hasLabel1
,
hasLabel2
)
{
expect
(
hasLabel1
).
toBeFalse
()
expect
(
hasLabel2
).
toBeFalse
()
done
()
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
article
.
hasLabel
(
label1
),
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
)
{
var
self
=
this
it
(
'answers true if the label has 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
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
[
article
,
'addLabel'
,
[
label1
]]
,
[
article
,
'hasLabel'
,
[
label1
]]
,
[
article
,
'hasLabel'
,
[
label2
]]
this
.
Article
.
create
({
title
:
'Article'
})
,
this
.
Label
.
create
({
text
:
'Awesomeness'
})
,
this
.
Label
.
create
({
text
:
'Epicness'
})
])
chainer
.
runSerially
().
success
(
function
(
_
,
label1
,
hasLabel1
,
hasLabel2
)
{
expect
(
hasLabel1
).
toBeTrue
()
expect
(
hasLabel2
).
toBeFalse
()
done
()
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
[
article
,
'addLabel'
,
[
label1
]],
[
article
,
'hasLabel'
,
[
label1
]],
[
article
,
'hasLabel'
,
[
label2
]]
])
chainer
.
runSerially
().
success
(
function
(
_
,
label1
,
hasLabel1
,
hasLabel2
)
{
expect
(
hasLabel1
).
toBeTrue
()
expect
(
hasLabel2
).
toBeFalse
()
done
()
})
})
})
})
})
describe
(
'hasAll'
,
function
()
{
before
(
function
(
done
)
{
this
.
Article
=
this
.
sequelize
.
define
(
'Article'
,
{
'title'
:
Sequelize
.
STRING
})
this
.
Label
=
this
.
sequelize
.
define
(
'Label'
,
{
'text'
:
Sequelize
.
STRING
})
describe
(
'hasAll'
,
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
)
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
)
{
var
self
=
this
it
(
'answers false if only some labels 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'
})
])
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
.
addLabel
(
label1
).
success
(
function
()
{
article
.
hasLabels
([
label1
,
label2
]).
success
(
function
(
result
)
{
expect
(
result
).
toBeFalse
()
done
()
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
article
.
addLabel
(
label1
).
success
(
function
()
{
article
.
hasLabels
([
label1
,
label2
]).
success
(
function
(
result
)
{
expect
(
result
).
toBeFalse
()
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
)
{
var
self
=
this
describe
(
'setAssociations'
,
function
()
{
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
([
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
])
Task
.
hasMany
(
User
)
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
()
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUsers
([
user
]).
success
(
function
()
{
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"
,
function
(
done
)
{
it
(
"clears associations when passing null to the set-method with omitNull set to true"
,
function
(
done
)
{
this
.
sequelize
.
options
.
omitNull
=
true
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
...
...
@@ -151,166 +183,138 @@ describe('HasMany', function() {
})
})
})
})
it
(
"clears associations when passing null to the set-method with omitNull set to true"
,
function
(
done
)
{
this
.
sequelize
.
options
.
omitNull
=
true
describe
(
"getting assocations with options"
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
;
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
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
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUsers
([
user
]).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
1
)
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
})
]
)
task
.
setUsers
(
null
).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
0
)
done
()
})
})
})
chainer
.
run
().
success
(
function
(
results
,
john
,
task1
,
task2
)
{
john
.
setTasks
([
task1
,
task2
]).
success
(
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
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
().
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
2
)
done
();
it
(
"gets all associated objects when no options are passed"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
().
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
2
)
done
();
})
})
})
})
it
(
"only get objects that fullfil the options"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
},
limit
:
10
,
order
:
'ID DESC'
}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
done
();
it
(
"only get objects that fullfil the options"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
},
limit
:
10
,
order
:
'ID DESC'
}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
done
();
})
})
})
})
})
})
describe
(
'(N:M)'
,
function
()
{
describe
(
"getting assocations with options"
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
;
describe
(
'(N:M)'
,
function
()
{
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
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
,
active
:
Sequelize
.
BOOLEAN
})
self
.
User
.
hasMany
(
self
.
Task
)
self
.
Task
.
hasMany
(
self
.
User
)
self
.
User
.
hasMany
(
self
.
Task
)
self
.
Task
.
hasMany
(
self
.
User
)
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
})
])
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
)
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
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
().
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
2
)
done
();
it
(
"gets all associated objects when no options are passed"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
().
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
2
)
done
();
})
})
})
})
it
(
"only get objects that fullfil the options"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
}}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
done
();
it
(
"only get objects that fullfil the options"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
}}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
done
();
})
})
})
})
})
it
(
"removes the reference id, which was added in the first place"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
it
(
"removes the reference id, which was added in the first place"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
)
expect
(
Task
.
attributes
.
UserId
).
toBeDefined
()
User
.
hasMany
(
Task
)
expect
(
Task
.
attributes
.
UserId
).
toBeDefined
()
Task
.
hasMany
(
User
)
expect
(
Task
.
attributes
.
UserId
).
not
.
toBeDefined
()
})
Task
.
hasMany
(
User
)
expect
(
Task
.
attributes
.
UserId
).
not
.
toBeDefined
()
})
it
(
"adds three items to the query chainer when calling sync"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
it
(
"adds three items to the query chainer when calling sync"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
)
Task
.
hasMany
(
User
)
User
.
hasMany
(
Task
)
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
})
expect
(
add
).
toHaveBeenCalledThrice
()
})
this
.
sequelize
.
sync
({
force
:
true
})
expect
(
add
).
toHaveBeenCalledThrice
()
})
describe
(
'setAssociations'
,
function
()
{
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
})
describe
(
'setAssociations'
,
function
()
{
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
})
User
.
hasMany
(
Task
)
Task
.
hasMany
(
User
)
User
.
hasMany
(
Task
)
Task
.
hasMany
(
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUsers
([
user
]).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
1
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUsers
([
user
]).
success
(
function
()
{
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
()
task
.
setUsers
(
null
).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
0
)
done
()
})
})
})
})
...
...
spec/associations/has-one.spec.js
View file @
4ecc546
...
...
@@ -2,42 +2,46 @@ if (typeof require === 'function') {
const
buster
=
require
(
"buster"
)
,
Sequelize
=
require
(
"../../index"
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
dialects
=
Helpers
.
getSupportedDialects
()
}
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
500
describe
(
'HasOne'
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
'HasOne@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
Helpers
.
initTests
({
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
onComplete
:
done
Helpers
.
initTests
({
dialect
:
dialect
,
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
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
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
()
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
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
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