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 a59c409e
authored
Oct 21, 2012
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't execute tests for every dialect but only for one per test run
1 parent
28f334e9
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
1224 additions
and
1211 deletions
changelog.md
package.json
spec/associations/belongs-to.spec.js
spec/associations/has-many.spec.js
spec/associations/has-one.spec.js
spec/associations/mixin.spec.js
spec/dao-factory.spec.js
spec/dao.spec.js
spec/dao.validations.spec.js
spec/query-chainer.spec.js
spec/sequelize.spec.js
spec/sqlite/dao.spec.js
changelog.md
View file @
a59c409
# v1.6.0 #
# v1.6.0 #
-
[
DEPENDENCIES
]
upgraded most dependencies. most important: mysql was upgraded to 2.0.0-alpha-3
-
[
DEPENDENCIES
]
upgraded most dependencies. most important: mysql was upgraded to 2.0.0-alpha-3
-
[
REFACTORING
]
separated tests for dialects
-
[
BUG
]
fixed wrong version in sequelize binary
-
[
BUG
]
fixed wrong version in sequelize binary
-
[
FEATURE
]
added association prefetching for find and findAll
-
[
FEATURE
]
added association prefetching for find and findAll
-
[
FEATURE
]
it's now possible to use callbacks of async functions inside migrations (thanks to mphilpot)
-
[
FEATURE
]
it's now possible to use callbacks of async functions inside migrations (thanks to mphilpot)
-
[
FEATURE
]
improved comfort of sequelize.query. just pass an sql string to it and wait for the result
-
[
FEATURE
]
improved comfort of sequelize.query. just pass an sql string to it and wait for the result
-
[
FEATURE
]
Migrations now understand NODE_ENV (thanks to gavri)
-
[
FEATURE
]
Migrations now understand NODE_ENV (thanks to gavri)
-
[
FEATURE
]
# v1.5.0 #
# v1.5.0 #
-
[
REFACTORING
]
use underscore functions for Utils.isHash (thanks to Mick-Hansen/innofluence)
-
[
REFACTORING
]
use underscore functions for Utils.isHash (thanks to Mick-Hansen/innofluence)
...
...
package.json
View file @
a59c409
...
@@ -48,7 +48,10 @@
...
@@ -48,7 +48,10 @@
"scripts"
:
{
"scripts"
:
{
"test"
:
"npm run test-jasmine && npm run test-buster"
,
"test"
:
"npm run test-jasmine && npm run test-buster"
,
"test-jasmine"
:
"./node_modules/.bin/jasmine-node spec-jasmine/"
,
"test-jasmine"
:
"./node_modules/.bin/jasmine-node spec-jasmine/"
,
"test-buster"
:
"./node_modules/.bin/buster-test"
,
"test-buster"
:
"npm run test-buster-mysql && npm run test-buster-postgres && npm run test-buster-sqlite"
,
"test-buster-mysql"
:
"DIALECT=mysql ./node_modules/.bin/buster-test"
,
"test-buster-postgres"
:
"DIALECT=postgres ./node_modules/.bin/buster-test"
,
"test-buster-sqlite"
:
"DIALECT=sqlite ./node_modules/.bin/buster-test"
,
"generate-docs"
:
"node_modules/.bin/dox-foundation --source ./lib --title Sequelize"
"generate-docs"
:
"node_modules/.bin/dox-foundation --source ./lib --title Sequelize"
},
},
"bin"
:
{
"bin"
:
{
...
...
spec/associations/belongs-to.spec.js
View file @
a59c409
...
@@ -2,45 +2,43 @@ if (typeof require === 'function') {
...
@@ -2,45 +2,43 @@ 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'
)
,
dialect
s
=
Helpers
.
getSupportedDialects
()
,
dialect
=
Helpers
.
getTestDialect
()
}
}
buster
.
spec
.
expose
()
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
500
buster
.
testRunner
.
timeout
=
500
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] BelongsTo"
,
function
()
{
describe
(
'BelongsTo@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
Helpers
.
initTests
({
beforeComplete
:
function
(
sequelize
)
{
beforeComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
this
.
sequelize
=
sequelize
}.
bind
(
this
),
}.
bind
(
this
),
onComplete
:
done
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 @
a59c409
...
@@ -2,163 +2,133 @@ if (typeof require === 'function') {
...
@@ -2,163 +2,133 @@ 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'
)
,
dialect
s
=
Helpers
.
getSupportedDialects
()
,
dialect
=
Helpers
.
getTestDialect
()
}
}
buster
.
spec
.
expose
()
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
500
buster
.
testRunner
.
timeout
=
500
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] HasMany"
,
function
()
{
describe
(
'HasMany@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
var
self
=
this
var
self
=
this
Helpers
.
initTests
({
Helpers
.
initTests
({
dialect
:
dialect
,
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
onComplete
:
done
onComplete
:
done
})
})
})
})
describe
(
'(1:N)'
,
function
()
{
describe
(
'(1:N)'
,
function
()
{
describe
(
'hasSingle'
,
function
()
{
describe
(
'hasSingle'
,
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
(
'does not have any labels assigned to it initially'
,
function
(
done
)
{
var
self
=
this
it
(
'does not have any labels assigned to it initially'
,
function
(
done
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
var
self
=
this
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
([
this
.
Article
.
create
({
title
:
'Article'
}),
article
.
hasLabel
(
label1
),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
article
.
hasLabel
(
label2
)
this
.
Label
.
create
({
text
:
'Epicness'
})
])
])
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
chainer
.
run
().
success
(
function
(
_
,
hasLabel1
,
hasLabel2
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
expect
(
hasLabel1
).
toBeFalse
()
article
.
hasLabel
(
label1
),
expect
(
hasLabel2
).
toBeFalse
()
article
.
hasLabel
(
label2
)
done
()
])
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
([
this
.
Article
.
create
({
title
:
'Article'
})
,
[
article
,
'addLabel'
,
[
label1
]]
,
this
.
Label
.
create
({
text
:
'Awesomeness'
})
,
[
article
,
'hasLabel'
,
[
label1
]]
,
this
.
Label
.
create
({
text
:
'Epicness'
})
[
article
,
'hasLabel'
,
[
label2
]]
])
])
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
chainer
.
runSerially
().
success
(
function
(
_
,
label1
,
hasLabel1
,
hasLabel2
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
expect
(
hasLabel1
).
toBeTrue
()
[
article
,
'addLabel'
,
[
label1
]],
expect
(
hasLabel2
).
toBeFalse
()
[
article
,
'hasLabel'
,
[
label1
]],
done
()
[
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
.
sequelize
.
sync
({
force
:
true
}).
success
(
done
)
})
it
(
'answers false if only some labels have been assigned'
,
function
(
done
)
{
this
.
Article
.
hasMany
(
this
.
Label
)
var
self
=
this
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
done
)
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
()
})
})
})
})
it
(
'answers true if all label
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
.
setLabels
([
label1
,
label2
]).
success
(
function
()
{
article
.
addLabel
(
label1
).
success
(
function
()
{
article
.
hasLabels
([
label1
,
label2
]).
success
(
function
(
result
)
{
article
.
hasLabels
([
label1
,
label2
]).
success
(
function
(
result
)
{
expect
(
result
).
toBeTrue
()
expect
(
result
).
toBeFalse
()
done
()
done
()
})
})
})
})
})
})
})
})
})
describe
(
'setAssociations'
,
function
()
{
it
(
'answers true if all label have been assigned'
,
function
(
done
)
{
it
(
"clears associations when passing null to the set-method"
,
function
(
done
)
{
var
self
=
this
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
Task
.
hasMany
(
User
)
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
])
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
article
.
setLabels
([
label1
,
label2
]).
success
(
function
()
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
article
.
hasLabels
([
label1
,
label2
]).
success
(
function
(
result
)
{
task
.
setUsers
([
user
]).
success
(
function
()
{
expect
(
result
).
toBeTrue
()
task
.
getUsers
().
success
(
function
(
_users
)
{
done
()
expect
(
_users
.
length
).
toEqual
(
1
)
task
.
setUsers
(
null
).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
0
)
done
()
})
})
})
})
})
})
})
})
})
})
})
})
})
})
it
(
"clears associations when passing null to the set-method with omitNull set to true"
,
function
(
done
)
{
describe
(
'setAssociations'
,
function
()
{
this
.
sequelize
.
options
.
omitNull
=
true
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
})
...
@@ -183,138 +153,166 @@ dialects.forEach(function(dialect) {
...
@@ -183,138 +153,166 @@ dialects.forEach(function(dialect) {
})
})
})
})
})
})
})
describe
(
"getting assocations with options"
,
function
()
{
it
(
"clears associations when passing null to the set-method with omitNull set to true"
,
function
(
done
)
{
before
(
function
(
done
)
{
this
.
sequelize
.
options
.
omitNull
=
true
var
self
=
this
;
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
,
active
:
Sequelize
.
BOOLEAN
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
this
.
User
.
hasMany
(
self
.
Task
)
Task
.
hasMany
(
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
()
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
self
.
User
.
create
({
username
:
'John'
}),
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
self
.
Task
.
create
({
title
:
'Get rich'
,
active
:
true
}),
task
.
setUsers
([
user
]).
success
(
function
()
{
self
.
Task
.
create
({
title
:
'Die trying'
,
active
:
false
})
task
.
getUsers
().
success
(
function
(
_users
)
{
]
)
expect
(
_users
.
length
).
toEqual
(
1
)
chainer
.
run
().
success
(
function
(
results
,
john
,
task1
,
task2
)
{
task
.
setUsers
(
null
).
success
(
function
()
{
john
.
setTasks
([
task1
,
task2
]).
success
(
done
)
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
0
)
done
()
})
})
})
})
})
})
})
})
})
})
})
it
(
"gets all associated objects when no options are passed"
,
function
(
done
)
{
describe
(
"getting assocations with options"
,
function
()
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
before
(
function
(
done
)
{
john
.
getTasks
().
success
(
function
(
tasks
)
{
var
self
=
this
;
expect
(
tasks
.
length
).
toEqual
(
2
)
done
();
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
(
"only get objects that fulfill the options"
,
function
(
done
)
{
it
(
"only get objects that fulfill 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 fulfill the options"
,
function
(
done
)
{
it
(
"only get objects that fulfill 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 @
a59c409
...
@@ -2,46 +2,44 @@ if (typeof require === 'function') {
...
@@ -2,46 +2,44 @@ 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'
)
,
dialect
s
=
Helpers
.
getSupportedDialects
()
,
dialect
=
Helpers
.
getTestDialect
()
}
}
buster
.
spec
.
expose
()
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
500
buster
.
testRunner
.
timeout
=
500
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] HasOne"
,
function
()
{
describe
(
'HasOne@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
var
self
=
this
var
self
=
this
Helpers
.
initTests
({
Helpers
.
initTests
({
dialect
:
dialect
,
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
onComplete
:
done
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
})
User
.
hasOne
(
Task
)
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
()
})
})
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
()
})
})
})
})
})
})
})
})
})
...
...
spec/associations/mixin.spec.js
View file @
a59c409
...
@@ -2,33 +2,31 @@ if (typeof require === 'function') {
...
@@ -2,33 +2,31 @@ 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'
)
,
dialect
s
=
Helpers
.
getSupportedDialects
()
,
dialect
=
Helpers
.
getTestDialect
()
}
}
buster
.
spec
.
expose
()
buster
.
spec
.
expose
()
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] Mixin"
,
function
()
{
describe
(
'Mixin@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
Helpers
.
initTests
({
dialect
:
dialect
,
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
)
{
beforeComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
this
.
sequelize
=
sequelize
}.
bind
(
this
),
}.
bind
(
this
),
onComplete
:
done
onComplete
:
done
})
})
})
})
describe
(
'getAssociation'
,
function
()
{
describe
(
'getAssociation'
,
function
()
{
it
(
'returns the respective part of the association for 1:1 associations'
,
function
()
{
it
(
'returns the respective part of the association for 1:1 associations'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{})
User
.
hasOne
(
Task
)
User
.
hasOne
(
Task
)
Task
.
belongsTo
(
User
)
Task
.
belongsTo
(
User
)
expect
(
User
.
getAssociation
(
Task
).
target
).
toEqual
(
Task
)
expect
(
User
.
getAssociation
(
Task
).
target
).
toEqual
(
Task
)
})
})
})
})
})
})
})
spec/dao-factory.spec.js
View file @
a59c409
...
@@ -2,117 +2,148 @@ if(typeof require === 'function') {
...
@@ -2,117 +2,148 @@ 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'
)
,
dialect
s
=
Helpers
.
getSupportedDialects
()
,
dialect
=
Helpers
.
getTestDialect
()
}
}
buster
.
spec
.
expose
()
buster
.
spec
.
expose
()
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] DAOFactory"
,
function
()
{
describe
(
'DAOFactory@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
Helpers
.
initTests
({
dialect
:
dialect
,
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
,
DataTypes
)
{
beforeComplete
:
function
(
sequelize
,
DataTypes
)
{
this
.
sequelize
=
sequelize
this
.
sequelize
=
sequelize
this
.
User
=
sequelize
.
define
(
'User'
,
{
this
.
User
=
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
,
username
:
DataTypes
.
STRING
,
secretValue
:
DataTypes
.
STRING
,
secretValue
:
DataTypes
.
STRING
,
data
:
DataTypes
.
STRING
data
:
DataTypes
.
STRING
})
})
}.
bind
(
this
),
}.
bind
(
this
),
onComplete
:
function
()
{
onComplete
:
function
(
sequelize
)
{
this
.
User
.
sync
({
force
:
true
}).
success
(
done
)
this
.
User
.
sync
({
force
:
true
}).
success
(
done
)
}.
bind
(
this
)
}.
bind
(
this
)
})
})
})
describe
(
'constructor'
,
function
()
{
it
(
"uses the passed dao name as tablename if freezeTableName"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'FrozenUser'
,
{},
{
freezeTableName
:
true
})
expect
(
User
.
tableName
).
toEqual
(
'FrozenUser'
)
})
})
describe
(
'constructor'
,
function
()
{
it
(
"uses the pluralized dao name as tablename unless freezeTableName"
,
function
()
{
it
(
"uses the passed dao name as tablename if freezeTableName"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'SuperUser'
,
{},
{
freezeTableName
:
false
})
var
User
=
this
.
sequelize
.
define
(
'FrozenUser'
,
{},
{
freezeTableName
:
true
})
expect
(
User
.
tableName
).
toEqual
(
'SuperUsers'
)
expect
(
User
.
tableName
).
toEqual
(
'FrozenUser'
)
})
})
it
(
"uses the pluralized dao name as tablename unless freezeTableName"
,
function
()
{
it
(
"attaches class and instance methods"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'SuperUser'
,
{},
{
freezeTableName
:
false
})
var
User
=
this
.
sequelize
.
define
(
'UserWithClassAndInstanceMethods'
,
{},
{
expect
(
User
.
tableName
).
toEqual
(
'SuperUsers'
)
classMethods
:
{
doSmth
:
function
(){
return
1
}
},
instanceMethods
:
{
makeItSo
:
function
(){
return
2
}}
})
})
it
(
"attaches class and instance methods"
,
function
()
{
expect
(
User
.
doSmth
).
toBeDefined
()
var
User
=
this
.
sequelize
.
define
(
'UserWithClassAndInstanceMethods'
,
{},
{
expect
(
User
.
doSmth
()).
toEqual
(
1
)
classMethods
:
{
doSmth
:
function
(){
return
1
}
},
expect
(
User
.
makeItSo
).
not
.
toBeDefined
()
instanceMethods
:
{
makeItSo
:
function
(){
return
2
}}
})
expect
(
User
.
doSmth
).
toBeDefined
()
expect
(
User
.
build
().
doSmth
).
not
.
toBeDefined
()
expect
(
User
.
doSmth
()).
toEqual
(
1
)
expect
(
User
.
build
().
makeItSo
).
toBeDefined
()
expect
(
User
.
makeItSo
).
not
.
toBeDefined
()
expect
(
User
.
build
().
makeItSo
()).
toEqual
(
2
)
})
expect
(
User
.
build
().
doSmth
).
not
.
toBeDefined
()
it
(
"throws an error if 2 autoIncrements are passed"
,
function
()
{
expect
(
User
.
build
().
makeItSo
).
toBeDefined
()
try
{
expect
(
User
.
build
().
makeItSo
()).
toEqual
(
2
)
var
User
=
this
.
sequelize
.
define
(
'UserWithTwoAutoIncrements'
,
{
})
userid
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
userscore
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
}
})
// the parse shouldn't execute the following line
// this tests needs to be refactored...
// we need to use expect.toThrow when a later version than 0.6 was released
expect
(
1
).
toEqual
(
2
)
}
catch
(
e
)
{
expect
(
e
.
message
).
toEqual
(
'Invalid DAO definition. Only one autoincrement field allowed.'
)
}
})
})
it
(
"throws an error if 2 autoIncrements are passed"
,
function
()
{
describe
(
'build'
,
function
()
{
try
{
it
(
"doesn't create database entries"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithTwoAutoIncrements'
,
{
this
.
User
.
build
({
username
:
'John Wayne'
})
userid
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
},
this
.
User
.
all
().
success
(
function
(
users
)
{
userscore
:
{
type
:
Sequelize
.
INTEGER
,
primaryKey
:
true
,
autoIncrement
:
true
}
expect
(
users
.
length
).
toEqual
(
0
)
})
done
()
// the parse shouldn't execute the following line
// this tests needs to be refactored...
// we need to use expect.toThrow when a later version than 0.6 was released
expect
(
1
).
toEqual
(
2
)
}
catch
(
e
)
{
expect
(
e
.
message
).
toEqual
(
'Invalid DAO definition. Only one autoincrement field allowed.'
)
}
})
})
})
})
describe
(
'build'
,
function
()
{
it
(
"fills the objects with default values"
,
function
()
{
it
(
"doesn't create database entries"
,
function
(
done
)
{
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
this
.
User
.
build
({
username
:
'John Wayne'
})
title
:
{
type
:
Sequelize
.
STRING
,
defaultValue
:
'a task!'
},
this
.
User
.
all
().
success
(
function
(
users
)
{
foo
:
{
type
:
Sequelize
.
INTEGER
,
defaultValue
:
2
},
expect
(
users
.
length
).
toEqual
(
0
)
bar
:
{
type
:
Sequelize
.
DATE
},
done
()
foobar
:
{
type
:
Sequelize
.
TEXT
,
defaultValue
:
'asd'
},
})
flag
:
{
type
:
Sequelize
.
BOOLEAN
,
defaultValue
:
false
}
})
expect
(
Task
.
build
().
title
).
toEqual
(
'a task!'
)
expect
(
Task
.
build
().
foo
).
toEqual
(
2
)
expect
(
Task
.
build
().
bar
).
toEqual
(
null
)
expect
(
Task
.
build
().
foobar
).
toEqual
(
'asd'
)
expect
(
Task
.
build
().
flag
).
toEqual
(
false
)
})
it
(
"stores the the passed values in a special variable"
,
function
()
{
var
user
=
this
.
User
.
build
({
username
:
'John Wayne'
})
expect
(
user
.
selectedValues
).
toEqual
({
username
:
'John Wayne'
})
})
})
describe
(
'create'
,
function
()
{
it
(
"doesn't allow duplicated records with unique:true"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithUniqueUsername'
,
{
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
}
})
})
it
(
"fills the objects with default values"
,
function
()
{
User
.
sync
({
force
:
true
}).
success
(
function
()
{
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
User
.
create
({
username
:
'foo'
}).
success
(
function
()
{
title
:
{
type
:
Sequelize
.
STRING
,
defaultValue
:
'a task!'
},
User
.
create
({
username
:
'foo'
}).
error
(
function
(
err
)
{
foo
:
{
type
:
Sequelize
.
INTEGER
,
defaultValue
:
2
},
expect
(
err
).
toBeDefined
()
bar
:
{
type
:
Sequelize
.
DATE
},
foobar
:
{
type
:
Sequelize
.
TEXT
,
defaultValue
:
'asd'
},
Helpers
.
checkMatchForDialects
(
dialect
,
err
.
message
,
{
flag
:
{
type
:
Sequelize
.
BOOLEAN
,
defaultValue
:
false
}
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
/.*Duplicate
\
entry.*/
,
postgres
:
/.*duplicate
\
key
\
value.*/
})
done
()
})
})
})
expect
(
Task
.
build
().
title
).
toEqual
(
'a task!'
)
expect
(
Task
.
build
().
foo
).
toEqual
(
2
)
expect
(
Task
.
build
().
bar
).
toEqual
(
null
)
expect
(
Task
.
build
().
foobar
).
toEqual
(
'asd'
)
expect
(
Task
.
build
().
flag
).
toEqual
(
false
)
})
})
})
it
(
"stores the the passed values in a special variable"
,
function
()
{
it
(
"raises an error if created object breaks definition contraints"
,
function
(
done
)
{
var
user
=
this
.
User
.
build
({
username
:
'John Wayne'
})
var
User
=
this
.
sequelize
.
define
(
'UserWithNonNullSmth'
,
{
expect
(
user
.
selectedValues
).
toEqual
({
username
:
'John Wayne'
})
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
})
})
describe
(
'create'
,
function
()
{
User
.
sync
({
force
:
true
}).
success
(
function
()
{
it
(
"doesn't allow duplicated records with unique:true"
,
function
(
done
)
{
User
.
create
({
username
:
'foo'
,
smth
:
null
}).
error
(
function
(
err
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithUniqueUsername'
,
{
expect
(
err
).
toBeDefined
()
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
}
})
Helpers
.
checkMatchForDialects
(
dialect
,
err
.
message
,
{
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
"Column 'smth' cannot be null"
,
postgres
:
/.*column "smth" violates not-null.*/
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
,
smth
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
,
smth
:
'bar'
}).
error
(
function
(
err
)
{
User
.
create
({
username
:
'foo'
}).
error
(
function
(
err
)
{
expect
(
err
).
toBeDefined
()
expect
(
err
).
toBeDefined
()
Helpers
.
checkMatchForDialects
(
dialect
,
err
.
message
,
{
Helpers
.
checkMatchForDialects
(
dialect
,
err
.
message
,
{
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
/.*Duplicate
\
entry.*/
,
mysql
:
"Duplicate entry 'foo' for key 'username'"
,
postgres
:
/.*duplicate
\
key
\
value
.*/
postgres
:
/.*duplicate
key value violates unique constraint
.*/
})
})
done
()
done
()
...
@@ -120,646 +151,629 @@ dialects.forEach(function(dialect) {
...
@@ -120,646 +151,629 @@ dialects.forEach(function(dialect) {
})
})
})
})
})
})
})
it
(
"raises an error if created object breaks definition contraints"
,
function
(
done
)
{
it
(
'sets auto increment fields'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithNonNullSmth'
,
{
var
User
=
this
.
sequelize
.
define
(
'UserWithAutoIncrementField'
,
{
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
userid
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
,
allowNull
:
false
}
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
,
smth
:
null
}).
error
(
function
(
err
)
{
expect
(
err
).
toBeDefined
()
Helpers
.
checkMatchForDialects
(
dialect
,
err
.
message
,
{
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
"Column 'smth' cannot be null"
,
postgres
:
/.*column "smth" violates not-null.*/
})
User
.
create
({
username
:
'foo'
,
smth
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
,
smth
:
'bar'
}).
error
(
function
(
err
)
{
expect
(
err
).
toBeDefined
()
Helpers
.
checkMatchForDialects
(
dialect
,
err
.
message
,
{
sqlite
:
/.*SQLITE_CONSTRAINT.*/
,
mysql
:
"Duplicate entry 'foo' for key 'username'"
,
postgres
:
/.*duplicate key value violates unique constraint.*/
})
done
()
})
})
})
})
})
})
it
(
'sets auto increment fields'
,
function
(
done
)
{
User
.
sync
({
force
:
true
}).
success
(
function
()
{
var
User
=
this
.
sequelize
.
define
(
'UserWithAutoIncrementField'
,
{
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
userid
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
,
allowNull
:
false
}
expect
(
user
.
userid
).
toEqual
(
1
)
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
expect
(
user
.
userid
).
toEqual
(
1
)
expect
(
user
.
userid
).
toEqual
(
2
)
done
()
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
expect
(
user
.
userid
).
toEqual
(
2
)
done
()
})
})
})
})
})
})
})
})
it
(
'allows the usage of options as attribute'
,
function
(
done
)
{
it
(
'allows the usage of options as attribute'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithNameAndOptions'
,
{
var
User
=
this
.
sequelize
.
define
(
'UserWithNameAndOptions'
,
{
name
:
Sequelize
.
STRING
,
name
:
Sequelize
.
STRING
,
options
:
Sequelize
.
TEXT
options
:
Sequelize
.
TEXT
})
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
name
:
'John Doe'
,
options
:
options
})
.
success
(
function
(
user
)
{
expect
(
user
.
options
).
toEqual
(
options
)
done
()
})
})
})
})
it
(
'allows sql logging'
,
function
(
done
)
{
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
})
var
User
=
this
.
sequelize
.
define
(
'UserWithUniqueNameAndNonNullSmth'
,
{
name
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
User
.
create
({
name
:
'Fluffy Bunny'
,
smth
:
'else'
})
.
create
({
name
:
'John Doe'
,
options
:
options
})
.
on
(
'sql'
,
function
(
sql
)
{
.
success
(
function
(
user
)
{
expect
(
sql
).
toBeDefined
()
expect
(
user
.
options
).
toEqual
(
options
)
expect
(
sql
.
toUpperCase
().
indexOf
(
"INSERT"
)).
toBeGreaterThan
(
-
1
)
done
()
done
()
})
})
})
})
})
})
it
(
'should only store the values passed in the witelist'
,
function
(
done
)
{
it
(
'allows sql logging'
,
function
(
done
)
{
var
self
=
this
var
User
=
this
.
sequelize
.
define
(
'UserWithUniqueNameAndNonNullSmth'
,
{
,
data
=
{
username
:
'Peter'
,
secretValue
:
'42'
}
name
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
this
.
User
.
create
(
data
,
[
'username'
]).
success
(
function
(
user
)
{
User
.
sync
({
force
:
true
}).
success
(
function
()
{
self
.
User
.
find
(
user
.
id
).
success
(
function
(
_user
)
{
User
expect
(
_user
.
username
).
toEqual
(
data
.
username
)
.
create
({
name
:
'Fluffy Bunny'
,
smth
:
'else'
})
expect
(
_user
.
secretValue
).
not
.
toEqual
(
data
.
secretValue
)
.
on
(
'sql'
,
function
(
sql
)
{
expect
(
_user
.
secretValue
).
toEqual
(
null
)
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"INSERT"
)).
toBeGreaterThan
(
-
1
)
done
()
done
()
})
})
})
})
})
})
it
(
'should store all values if no whitelist is specified
'
,
function
(
done
)
{
it
(
'should only store the values passed in the witelist
'
,
function
(
done
)
{
var
self
=
this
var
self
=
this
,
data
=
{
username
:
'Peter'
,
secretValue
:
'42'
}
,
data
=
{
username
:
'Peter'
,
secretValue
:
'42'
}
this
.
User
.
create
(
data
).
success
(
function
(
user
)
{
this
.
User
.
create
(
data
,
[
'username'
]
).
success
(
function
(
user
)
{
self
.
User
.
find
(
user
.
id
).
success
(
function
(
_user
)
{
self
.
User
.
find
(
user
.
id
).
success
(
function
(
_user
)
{
expect
(
_user
.
username
).
toEqual
(
data
.
username
)
expect
(
_user
.
username
).
toEqual
(
data
.
username
)
expect
(
_user
.
secretValue
)
.
toEqual
(
data
.
secretValue
)
expect
(
_user
.
secretValue
).
not
.
toEqual
(
data
.
secretValue
)
done
(
)
expect
(
_user
.
secretValue
).
toEqual
(
null
)
}
)
done
(
)
})
})
})
})
})
it
(
'saves data with single quote'
,
function
(
done
)
{
it
(
'should store all values if no whitelist is specified'
,
function
(
done
)
{
var
quote
=
"single'quote"
var
self
=
this
,
self
=
this
,
data
=
{
username
:
'Peter'
,
secretValue
:
'42'
}
this
.
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'memory single quote'
)
self
.
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
this
.
User
.
create
(
data
).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'SQL single quote'
)
self
.
User
.
find
(
user
.
id
).
success
(
function
(
_user
)
{
done
()
expect
(
_user
.
username
).
toEqual
(
data
.
username
)
})
expect
(
_user
.
secretValue
).
toEqual
(
data
.
secretValue
)
done
()
})
})
})
})
})
it
(
'saves data with doub
le quote'
,
function
(
done
)
{
it
(
'saves data with sing
le quote'
,
function
(
done
)
{
var
quote
=
'double"quote'
var
quote
=
"single'quote"
,
self
=
this
,
self
=
this
this
.
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
this
.
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'memory doub
le quote'
)
expect
(
user
.
data
).
toEqual
(
quote
,
'memory sing
le quote'
)
self
.
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
self
.
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'SQL double quote'
)
expect
(
user
.
data
).
toEqual
(
quote
,
'SQL single quote'
)
done
()
done
()
})
})
})
})
})
})
it
(
'saves stringified JSON data
'
,
function
(
done
)
{
it
(
'saves data with double quote
'
,
function
(
done
)
{
var
json
=
JSON
.
stringify
({
key
:
'value'
})
var
quote
=
'double"quote'
,
self
=
this
,
self
=
this
this
.
User
.
create
({
data
:
json
}).
success
(
function
(
user
)
{
this
.
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
json
,
'memory data
'
)
expect
(
user
.
data
).
toEqual
(
quote
,
'memory double quote
'
)
self
.
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
json
,
'SQL data'
)
self
.
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
done
(
)
expect
(
user
.
data
).
toEqual
(
quote
,
'SQL double quote'
)
}
)
done
(
)
})
})
})
})
})
it
(
'stores the current date in createdAt'
,
function
(
done
)
{
it
(
'saves stringified JSON data'
,
function
(
done
)
{
this
.
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
var
json
=
JSON
.
stringify
({
key
:
'value'
})
expect
(
parseInt
(
+
user
.
createdAt
/
5000
)).
toEqual
(
parseInt
(
+
new
Date
()
/
5000
))
,
self
=
this
this
.
User
.
create
({
data
:
json
}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
json
,
'memory data'
)
self
.
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
json
,
'SQL data'
)
done
()
done
()
})
})
})
})
})
})
describe
(
'find'
,
function
find
()
{
it
(
'stores the current date in createdAt'
,
function
(
done
)
{
before
(
function
(
done
)
{
this
.
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
this
.
User
.
create
({
expect
(
parseInt
(
+
user
.
createdAt
/
5000
)).
toEqual
(
parseInt
(
+
new
Date
()
/
5000
))
username
:
'barfooz'
done
()
}).
success
(
function
(
user
)
{
this
.
user
=
user
done
()
}.
bind
(
this
))
})
})
})
})
it
(
'returns a single dao'
,
function
(
done
)
{
describe
(
'find'
,
function
find
()
{
this
.
User
.
find
(
this
.
user
.
id
).
success
(
function
(
user
)
{
before
(
function
(
done
)
{
expect
(
Array
.
isArray
(
user
)).
toBeFalsy
()
this
.
User
.
create
({
expect
(
user
.
id
).
toEqual
(
this
.
user
.
id
)
username
:
'barfooz'
expect
(
user
.
id
).
toEqual
(
1
)
}).
success
(
function
(
user
)
{
done
()
this
.
user
=
user
}.
bind
(
this
))
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
(
"should make aliased attributes available"
,
function
(
done
)
{
it
(
'finds a specific user via where option'
,
function
(
done
)
{
this
.
User
.
find
({
this
.
User
.
find
({
where
:
{
username
:
'barfooz'
}
}).
success
(
function
(
user
)
{
where
:
{
id
:
1
},
expect
(
user
.
username
).
toEqual
(
'barfooz'
)
attributes
:
[
'id'
,
[
'username'
,
'name'
]]
done
()
}).
success
(
function
(
user
)
{
expect
(
user
.
name
).
toEqual
(
'barfooz'
)
done
()
})
})
})
})
it
(
'finds a specific user via where option'
,
function
(
done
)
{
it
(
"doesn't find a user if conditions are not matching"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'barfooz'
}
}).
success
(
function
(
user
)
{
this
.
User
.
find
({
where
:
{
username
:
'foo'
}
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'barfooz'
)
expect
(
user
).
toBeNull
()
done
()
done
()
})
})
})
})
it
(
"doesn't find a user if conditions are not matching"
,
function
(
done
)
{
it
(
'allows sql logging'
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'foo'
}
}).
success
(
function
(
user
)
{
this
.
User
.
find
({
where
:
{
username
:
'foo'
}
})
expect
(
user
).
toBeNull
()
.
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
done
()
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
(
'allows sql logging'
,
function
(
done
)
{
it
(
'finds entries via primary keys'
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'foo'
}
})
var
User
=
this
.
sequelize
.
define
(
'UserWithPrimaryKey'
,
{
.
on
(
'sql'
,
function
(
sql
)
{
identifier
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
},
expect
(
sql
).
toBeDefined
()
name
:
Sequelize
.
STRING
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
})
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
()
done
()
})
})
})
})
})
})
it
(
'ignores passed limit option'
,
function
(
done
)
{
it
(
'//returns the selected fields as instance.selectedValues'
,
function
(
done
)
{
this
.
User
.
find
({
limit
:
10
}).
success
(
function
(
user
)
{
this
.
User
.
create
({
// it returns an object instead of an array
username
:
'JohnXOXOXO'
expect
(
Array
.
isArray
(
user
)).
toBeFalsy
()
}).
success
(
function
()
{
expect
(
user
.
hasOwnProperty
(
'username'
)).
toBeTruthy
()
this
.
User
.
find
({
where
:
{
username
:
'JohnXOXOXO'
},
select
:
[
'username'
]
}).
success
(
function
(
user
)
{
expect
(
user
.
selectedValues
).
toEqual
({
username
:
'JohnXOXOXO'
})
done
()
done
()
})
})
})
}.
bind
(
this
))
})
it
(
'finds entries via primary keys'
,
function
(
done
)
{
describe
(
'association fetching'
,
function
(
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithPrimaryKey'
,
{
before
(
function
()
{
identifier
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
},
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
nam
e
:
Sequelize
.
STRING
titl
e
:
Sequelize
.
STRING
})
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
=
this
.
sequelize
.
define
(
'UserWithName'
,
{
User
.
create
({
name
:
Sequelize
.
STRING
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
()
})
})
})
})
})
})
describe
(
'association fetching'
,
function
()
{
it
(
'fetches associated objects for 1:1 associations (1st direction)'
,
function
(
done
)
{
before
(
function
()
{
this
.
User
.
hasOne
(
this
.
Task
)
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
this
.
Task
.
belongsTo
(
this
.
User
)
title
:
Sequelize
.
STRING
})
this
.
User
=
this
.
sequelize
.
define
(
'UserWithName'
,
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
name
:
Sequelize
.
STRING
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:1
associations (1st direction)'
,
function
(
done
)
{
it
(
'fetches associated objects for 1:N
associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasOne
(
this
.
Task
)
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
user
.
setTask
(
task
).
success
(
function
()
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
User
.
find
({
this
.
User
.
find
({
where
:
{
'UserWithNames.id'
:
1
},
where
:
{
'UserWithNames.id'
:
1
},
include
:
[
'Task'
]
include
:
[
'Task'
]
}).
success
(
function
(
user
)
{
}).
success
(
function
(
user
)
{
expect
(
user
.
task
).
toBeDefined
()
expect
(
user
.
tasks
).
toBeDefined
()
expect
(
user
.
task
.
id
).
toEqual
(
task
.
id
)
expect
(
user
.
tasks
.
map
(
function
(
t
)
{
return
t
.
id
})
).
toEqual
(
[
task1
.
id
,
task2
.
id
]
)
done
()
done
()
})
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- sequelize.sync
}.
bind
(
this
))
//- User.create
})
}.
bind
(
this
))
//- sequelize.sync
})
it
(
'fetches associated objects for 1:1
associations (2nd direction)'
,
function
(
done
)
{
it
(
'fetches associated objects for 1:N
associations (2nd direction)'
,
function
(
done
)
{
this
.
User
.
hasOne
(
this
.
Task
)
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
user
.
setTask
(
task
).
success
(
function
()
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
Task
.
find
({
this
.
Task
.
find
({
where
:
{
'Tasks.id'
:
1
},
where
:
{
'Tasks.id'
:
1
},
include
:
[
'UserWithName'
]
include
:
[
'UserWithName'
]
}).
success
(
function
(
task
)
{
}).
success
(
function
(
task
)
{
expect
(
task
.
userWithName
).
toBeDefined
()
expect
(
task
.
userWithName
).
toBeDefined
()
expect
(
task
.
userWithName
.
id
).
toEqual
(
user
.
id
)
expect
(
task
.
userWithName
.
name
).
toEqual
(
user
.
name
)
done
()
done
()
})
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- sequelize.sync
}.
bind
(
this
))
//- User.create
})
}.
bind
(
this
))
//- sequelize.sync
})
it
(
'fetches associated objects for 1:N associations (1st direction)'
,
function
(
done
)
{
it
(
'fetches associated objects for N:M associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
Task
.
hasMany
(
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
})
it
(
'fetches associated objects for 1:N associations (2nd direction)'
,
function
(
done
)
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
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
.
Task
.
find
({
where
:
{
'Tasks.id'
:
1
},
include
:
[
'UserWithName'
]
}).
success
(
function
(
task
)
{
expect
(
task
.
userWithName
).
toBeDefined
()
expect
(
task
.
userWithName
.
name
).
toEqual
(
user
.
name
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
it
(
'fetches associated objects for N:M associations (1st direction)'
,
function
(
done
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
this
.
Task
.
hasMany
(
this
.
User
)
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
User
.
find
({
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
where
:
{
'UserWithNames.id'
:
user1
.
id
},
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
include
:
[
'Task'
]
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
expect
(
user
.
tasks
).
toBeDefined
()
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
expect
(
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
user
.
tasks
.
map
(
function
(
t
)
{
return
t
.
id
})
this
.
User
.
find
({
).
toEqual
(
where
:
{
'UserWithNames.id'
:
user1
.
id
},
[
task1
.
id
,
task2
.
id
]
include
:
[
'Task'
]
)
}).
success
(
function
(
user
)
{
done
()
expect
(
user
.
tasks
).
toBeDefined
()
})
expect
(
}.
bind
(
this
))
//- setTask
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
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
}.
bind
(
this
))
//- sequelize.sync
})
})
it
(
'fetches associated objects for N:M associations (2nd direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
hasMany
(
this
.
User
)
it
(
'fetches associated objects for N:M associations (2nd direction)'
,
function
(
done
)
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
this
.
Task
.
hasMany
(
this
.
User
)
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
Task
.
find
({
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
where
:
{
'Tasks.id'
:
task1
.
id
},
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
include
:
[
'UserWithName'
]
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
}).
success
(
function
(
task
)
{
this
.
Task
.
find
({
expect
(
task
.
userWithNames
).
toBeDefined
()
where
:
{
'Tasks.id'
:
task1
.
id
},
expect
(
include
:
[
'UserWithName'
]
task
.
userWithNames
.
map
(
function
(
u
)
{
return
u
.
id
})
}).
success
(
function
(
task
)
{
).
toEqual
(
expect
(
task
.
userWithNames
).
toBeDefined
()
[
user1
.
id
]
expect
(
)
task
.
userWithNames
.
map
(
function
(
u
)
{
return
u
.
id
})
done
()
).
toEqual
(
})
[
user1
.
id
]
}.
bind
(
this
))
//- setTask
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
}.
bind
(
this
))
//- sequelize.sync
})
})
})
})
//- describe: find
})
describe
(
'findAll'
,
function
findAll
()
{
describe
(
'association fetching'
,
function
()
{
before
(
function
()
{
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
this
.
User
=
this
.
sequelize
.
define
(
'UserWithName'
,
{
})
//- describe: find
name
:
Sequelize
.
STRING
})
describe
(
'findAll'
,
function
findAll
()
{
describe
(
'association fetching'
,
function
()
{
before
(
function
()
{
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
.
findAll
({
where
:
{
'UserWithNames.id'
:
1
},
include
:
[
'Task'
]
}).
success
(
function
(
users
)
{
expect
(
users
[
0
].
task
).
toBeDefined
()
expect
(
users
[
0
].
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
.
findAll
({
where
:
{
'Tasks.id'
:
1
},
include
:
[
'UserWithName'
]
}).
success
(
function
(
tasks
)
{
expect
(
tasks
[
0
].
userWithName
).
toBeDefined
()
expect
(
tasks
[
0
].
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:1
associations (1st direction)'
,
function
(
done
)
{
it
(
'fetches associated objects for 1:N
associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasOne
(
this
.
Task
)
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
user
.
setTask
(
task
).
success
(
function
()
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
User
.
findAll
({
this
.
User
.
findAll
({
where
:
{
'UserWithNames.id'
:
1
},
where
:
{
'UserWithNames.id'
:
1
},
include
:
[
'Task'
]
include
:
[
'Task'
]
}).
success
(
function
(
users
)
{
}).
success
(
function
(
users
)
{
expect
(
users
[
0
].
task
).
toBeDefined
()
expect
(
users
[
0
].
tasks
).
toBeDefined
()
expect
(
users
[
0
].
task
.
id
).
toEqual
(
task
.
id
)
expect
(
users
[
0
].
tasks
.
map
(
function
(
t
)
{
return
t
.
id
})
).
toEqual
(
[
task1
.
id
,
task2
.
id
]
)
done
()
done
()
})
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- sequelize.sync
}.
bind
(
this
))
//- User.create
})
}.
bind
(
this
))
//- sequelize.sync
})
it
(
'fetches associated objects for 1:1
associations (2nd direction)'
,
function
(
done
)
{
it
(
'fetches associated objects for 1:N
associations (2nd direction)'
,
function
(
done
)
{
this
.
User
.
hasOne
(
this
.
Task
)
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
user
.
setTask
(
task
).
success
(
function
()
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
Task
.
findAll
({
this
.
Task
.
findAll
({
where
:
{
'Tasks.id'
:
1
},
where
:
{
'Tasks.id'
:
1
},
include
:
[
'UserWithName'
]
include
:
[
'UserWithName'
]
}).
success
(
function
(
tasks
)
{
}).
success
(
function
(
tasks
)
{
expect
(
tasks
[
0
].
userWithName
).
toBeDefined
()
expect
(
tasks
[
0
].
userWithName
).
toBeDefined
()
expect
(
tasks
[
0
].
userWithName
.
id
).
toEqual
(
user
.
id
)
expect
(
tasks
[
0
].
userWithName
.
name
).
toEqual
(
user
.
name
)
done
()
done
()
})
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- sequelize.sync
}.
bind
(
this
))
//- User.create
})
}.
bind
(
this
))
//- sequelize.sync
})
it
(
'fetches associated objects for 1:N associations (1st direction)'
,
function
(
done
)
{
it
(
'fetches associated objects for N:M associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
Task
.
hasMany
(
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
.
findAll
({
where
:
{
'UserWithNames.id'
:
1
},
include
:
[
'Task'
]
}).
success
(
function
(
users
)
{
expect
(
users
[
0
].
tasks
).
toBeDefined
()
expect
(
users
[
0
].
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
})
it
(
'fetches associated objects for 1:N associations (2nd direction)'
,
function
(
done
)
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
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
.
Task
.
findAll
({
where
:
{
'Tasks.id'
:
1
},
include
:
[
'UserWithName'
]
}).
success
(
function
(
tasks
)
{
expect
(
tasks
[
0
].
userWithName
).
toBeDefined
()
expect
(
tasks
[
0
].
userWithName
.
name
).
toEqual
(
user
.
name
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
it
(
'fetches associated objects for N:M associations (1st direction)'
,
function
(
done
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
this
.
Task
.
hasMany
(
this
.
User
)
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
User
.
findAll
({
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
where
:
{
'UserWithNames.id'
:
user1
.
id
},
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
include
:
[
'Task'
]
}).
success
(
function
(
users
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
expect
(
users
[
0
].
tasks
).
toBeDefined
()
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
expect
(
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
users
[
0
].
tasks
.
map
(
function
(
t
)
{
return
t
.
id
})
this
.
User
.
findAll
({
).
toEqual
(
where
:
{
'UserWithNames.id'
:
user1
.
id
},
[
task1
.
id
,
task2
.
id
]
include
:
[
'Task'
]
)
}).
success
(
function
(
users
)
{
done
()
expect
(
users
[
0
].
tasks
).
toBeDefined
()
})
expect
(
}.
bind
(
this
))
//- setTask
users
[
0
].
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
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
}.
bind
(
this
))
//- sequelize.sync
})
})
it
(
'fetches associated objects for N:M associations (2nd direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
hasMany
(
this
.
User
)
it
(
'fetches associated objects for N:M associations (2nd direction)'
,
function
(
done
)
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
this
.
Task
.
hasMany
(
this
.
User
)
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
Task
.
findAll
({
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
where
:
{
'Tasks.id'
:
task1
.
id
},
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
include
:
[
'UserWithName'
]
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
}).
success
(
function
(
tasks
)
{
this
.
Task
.
findAll
({
expect
(
tasks
[
0
].
userWithNames
).
toBeDefined
()
where
:
{
'Tasks.id'
:
task1
.
id
},
expect
(
include
:
[
'UserWithName'
]
tasks
[
0
].
userWithNames
.
map
(
function
(
u
)
{
return
u
.
id
})
}).
success
(
function
(
tasks
)
{
).
toEqual
(
expect
(
tasks
[
0
].
userWithNames
).
toBeDefined
()
[
user1
.
id
]
expect
(
)
tasks
[
0
].
userWithNames
.
map
(
function
(
u
)
{
return
u
.
id
})
done
()
).
toEqual
(
})
[
user1
.
id
]
}.
bind
(
this
))
//- setTask
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
}.
bind
(
this
))
//- sequelize.sync
})
})
})
})
//- describe: findAll
})
})
//- describe: findAll
describe
(
'min'
,
function
()
{
before
(
function
(
done
)
{
this
.
UserWithAge
=
this
.
sequelize
.
define
(
'UserWithAge'
,
{
age
:
Sequelize
.
INTEGER
})
this
.
UserWithAge
.
sync
({
force
:
true
}).
success
(
done
)
describe
(
'min'
,
function
()
{
before
(
function
(
done
)
{
this
.
UserWithAge
=
this
.
sequelize
.
define
(
'UserWithAge'
,
{
age
:
Sequelize
.
INTEGER
})
})
it
(
"should return the min value"
,
function
(
done
)
{
this
.
UserWithAge
.
sync
({
force
:
true
}).
success
(
done
)
this
.
UserWithAge
.
create
({
age
:
2
}).
success
(
function
()
{
})
this
.
UserWithAge
.
create
({
age
:
3
}).
success
(
function
()
{
this
.
UserWithAge
.
min
(
'age'
).
success
(
function
(
min
)
{
it
(
"should return the min value"
,
function
(
done
)
{
expect
(
min
).
toEqual
(
2
)
this
.
UserWithAge
.
create
({
age
:
2
}).
success
(
function
()
{
done
()
this
.
UserWithAge
.
create
({
age
:
3
}).
success
(
function
()
{
})
this
.
UserWithAge
.
min
(
'age'
).
success
(
function
(
min
)
{
}.
bind
(
this
))
expect
(
min
).
toEqual
(
2
)
done
()
})
}.
bind
(
this
))
}.
bind
(
this
))
})
}.
bind
(
this
))
})
it
(
'allows sql logging'
,
function
(
done
)
{
it
(
'allows sql logging'
,
function
(
done
)
{
this
.
UserWithAge
.
min
(
'age'
).
on
(
'sql'
,
function
(
sql
)
{
this
.
UserWithAge
.
min
(
'age'
).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
done
()
done
()
})
})
})
})
//- describe: min
})
})
//- describe: min
describe
(
'max'
,
function
()
{
before
(
function
(
done
)
{
this
.
UserWithAge
=
this
.
sequelize
.
define
(
'UserWithAge'
,
{
age
:
Sequelize
.
INTEGER
})
this
.
UserWithAge
.
sync
({
force
:
true
}).
success
(
done
)
describe
(
'max'
,
function
()
{
before
(
function
(
done
)
{
this
.
UserWithAge
=
this
.
sequelize
.
define
(
'UserWithAge'
,
{
age
:
Sequelize
.
INTEGER
})
})
it
(
"should return the max value"
,
function
(
done
)
{
this
.
UserWithAge
.
sync
({
force
:
true
}).
success
(
done
)
this
.
UserWithAge
.
create
({
age
:
2
}).
success
(
function
()
{
})
this
.
UserWithAge
.
create
({
age
:
3
}).
success
(
function
()
{
this
.
UserWithAge
.
max
(
'age'
).
success
(
function
(
max
)
{
it
(
"should return the max value"
,
function
(
done
)
{
expect
(
max
).
toEqual
(
3
)
this
.
UserWithAge
.
create
({
age
:
2
}).
success
(
function
()
{
done
()
this
.
UserWithAge
.
create
({
age
:
3
}).
success
(
function
()
{
})
this
.
UserWithAge
.
max
(
'age'
).
success
(
function
(
max
)
{
}.
bind
(
this
))
expect
(
max
).
toEqual
(
3
)
done
()
})
}.
bind
(
this
))
}.
bind
(
this
))
})
}.
bind
(
this
))
})
it
(
'allows sql logging'
,
function
(
done
)
{
it
(
'allows sql logging'
,
function
(
done
)
{
this
.
UserWithAge
.
max
(
'age'
).
on
(
'sql'
,
function
(
sql
)
{
this
.
UserWithAge
.
max
(
'age'
).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
done
()
done
()
})
})
})
})
//- describe: max
})
})
})
//- describe: max
})
})
spec/dao.spec.js
View file @
a59c409
if
(
typeof
require
===
'function'
)
{
if
(
typeof
require
===
'function'
)
{
const
buster
=
require
(
"buster"
)
const
buster
=
require
(
"buster"
)
,
dialects
=
[
'sqlite'
,
'mysql'
,
'postgres'
]
,
Helpers
=
require
(
'./buster-helpers'
)
,
Helpers
=
require
(
'./buster-helpers'
)
,
dialect
=
Helpers
.
getTestDialect
(
)
}
}
buster
.
spec
.
expose
()
buster
.
spec
.
expose
()
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] DAO"
,
function
()
{
describe
(
'DAO@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
var
self
=
this
var
self
=
this
Helpers
.
initTests
({
Helpers
.
initTests
({
dialect
:
dialect
,
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
,
DataTypes
)
{
beforeComplete
:
function
(
sequelize
,
DataTypes
)
{
self
.
sequelize
=
sequelize
self
.
sequelize
=
sequelize
self
.
User
=
sequelize
.
define
(
'User'
,
{
self
.
User
=
sequelize
.
define
(
'User'
,
{
username
:
{
type
:
DataTypes
.
STRING
},
username
:
{
type
:
DataTypes
.
STRING
},
touchedAt
:
{
type
:
DataTypes
.
DATE
,
defaultValue
:
DataTypes
.
NOW
},
touchedAt
:
{
type
:
DataTypes
.
DATE
,
defaultValue
:
DataTypes
.
NOW
},
aNumber
:
{
type
:
DataTypes
.
INTEGER
}
aNumber
:
{
type
:
DataTypes
.
INTEGER
}
})
})
},
},
onComplete
:
function
(
sequelize
)
{
onComplete
:
function
()
{
self
.
User
.
sync
({
force
:
true
}).
success
(
done
)
self
.
User
.
sync
({
force
:
true
}).
success
(
done
)
}
}
})
})
})
})
describe
(
'default values'
,
function
()
{
describe
(
'default values'
,
function
()
{
describe
(
'current date'
,
function
()
{
describe
(
'current date'
,
function
()
{
it
(
'should store a date in touchedAt'
,
function
()
{
it
(
'should store a date in touchedAt'
,
function
()
{
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
expect
(
user
.
touchedAt
instanceof
Date
).
toBeTrue
()
expect
(
user
.
touchedAt
instanceof
Date
).
toBeTrue
()
})
})
it
(
"should store the current date in touchedAt"
,
function
()
{
it
(
"should store the current date in touchedAt"
,
function
()
{
this
.
useFakeTimers
().
tick
(
5000
)
this
.
useFakeTimers
().
tick
(
5000
)
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
expect
(
+
user
.
touchedAt
).
toBe
(
5000
)
expect
(
+
user
.
touchedAt
).
toBe
(
5000
)
})
})
})
})
})
})
describe
(
'complete'
,
function
()
{
describe
(
'complete'
,
function
()
{
it
(
"gets triggered if an error occurs"
,
function
(
done
)
{
it
(
"gets triggered if an error occurs"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
"asdasdasd"
}).
complete
(
function
(
err
,
result
)
{
this
.
User
.
find
({
where
:
"asdasdasd"
}).
complete
(
function
(
err
,
result
)
{
expect
(
err
).
toBeDefined
()
expect
(
err
).
toBeDefined
()
expect
(
err
.
message
).
toBeDefined
()
expect
(
err
.
message
).
toBeDefined
()
done
()
done
()
})
})
})
})
it
(
"gets triggered if everything was ok"
,
function
(
done
)
{
it
(
"gets triggered if everything was ok"
,
function
(
done
)
{
this
.
User
.
count
().
complete
(
function
(
err
,
result
)
{
this
.
User
.
count
().
complete
(
function
(
err
,
result
)
{
expect
(
err
).
toBeNull
()
expect
(
err
).
toBeNull
()
expect
(
result
).
toBeDefined
()
expect
(
result
).
toBeDefined
()
done
()
done
()
})
})
})
})
})
})
describe
(
'save'
,
function
()
{
describe
(
'save'
,
function
()
{
it
(
'takes zero into account'
,
function
(
done
)
{
it
(
'takes zero into account'
,
function
(
done
)
{
this
.
User
.
build
({
aNumber
:
0
}).
save
([
'aNumber'
]).
success
(
function
(
user
)
{
this
.
User
.
build
({
aNumber
:
0
}).
save
([
'aNumber'
]).
success
(
function
(
user
)
{
expect
(
user
.
aNumber
).
toEqual
(
0
)
expect
(
user
.
aNumber
).
toEqual
(
0
)
done
()
done
()
})
})
})
})
})
})
describe
(
'toJSON'
,
function
toJSON
()
{
describe
(
'toJSON'
,
function
toJSON
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
this
.
User
=
this
.
sequelize
.
define
(
'UserWithUsernameAndAgeAndIsAdmin'
,
{
this
.
User
=
this
.
sequelize
.
define
(
'UserWithUsernameAndAgeAndIsAdmin'
,
{
username
:
Helpers
.
Sequelize
.
STRING
,
username
:
Helpers
.
Sequelize
.
STRING
,
age
:
Helpers
.
Sequelize
.
INTEGER
,
age
:
Helpers
.
Sequelize
.
INTEGER
,
isAdmin
:
Helpers
.
Sequelize
.
BOOLEAN
isAdmin
:
Helpers
.
Sequelize
.
BOOLEAN
},
{
},
{
timestamps
:
false
,
timestamps
:
false
,
logging
:
true
logging
:
true
})
this
.
User
.
sync
({
force
:
true
}).
success
(
done
)
})
})
it
(
'returns an object containing all values'
,
function
()
{
this
.
User
.
sync
({
force
:
true
}).
success
(
done
)
var
user
=
this
.
User
.
build
({
username
:
'test.user'
,
age
:
99
,
isAdmin
:
true
})
})
expect
(
user
.
toJSON
()).
toEqual
({
username
:
'test.user'
,
age
:
99
,
isAdmin
:
true
,
id
:
null
})
})
it
(
'returns a response that can be stringified
'
,
function
()
{
it
(
'returns an object containing all values
'
,
function
()
{
var
user
=
this
.
User
.
build
({
username
:
'test.user'
,
age
:
99
,
isAdmin
:
true
})
var
user
=
this
.
User
.
build
({
username
:
'test.user'
,
age
:
99
,
isAdmin
:
true
})
expect
(
JSON
.
stringify
(
user
)).
toEqual
(
'{"username":"test.user","age":99,"isAdmin":true,"id":null}'
)
expect
(
user
.
toJSON
()).
toEqual
({
username
:
'test.user'
,
age
:
99
,
isAdmin
:
true
,
id
:
null
}
)
})
})
it
(
'returns a response that can be stringified and then parsed'
,
function
()
{
it
(
'returns a response that can be stringified'
,
function
()
{
var
user
=
this
.
User
.
build
({
username
:
'test.user'
,
age
:
99
,
isAdmin
:
true
})
var
user
=
this
.
User
.
build
({
username
:
'test.user'
,
age
:
99
,
isAdmin
:
true
})
expect
(
JSON
.
parse
(
JSON
.
stringify
(
user
))).
toEqual
({
username
:
'test.user'
,
age
:
99
,
isAdmin
:
true
,
id
:
null
})
expect
(
JSON
.
stringify
(
user
)).
toEqual
(
'{"username":"test.user","age":99,"isAdmin":true,"id":null}'
)
})
})
it
(
'returns a response that can be stringified and then parsed'
,
function
()
{
var
user
=
this
.
User
.
build
({
username
:
'test.user'
,
age
:
99
,
isAdmin
:
true
})
expect
(
JSON
.
parse
(
JSON
.
stringify
(
user
))).
toEqual
({
username
:
'test.user'
,
age
:
99
,
isAdmin
:
true
,
id
:
null
})
})
})
})
})
})
})
spec/dao.validations.spec.js
View file @
a59c409
...
@@ -7,262 +7,260 @@ if(typeof require === 'function') {
...
@@ -7,262 +7,260 @@ if(typeof require === 'function') {
buster
.
spec
.
expose
()
buster
.
spec
.
expose
()
describe
(
dialect
,
function
()
{
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] DAO"
,
function
()
{
describe
(
'=>DAO'
,
function
()
{
describe
(
'validations'
,
function
()
{
describe
(
'validations'
,
function
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
Helpers
.
initTests
({
dialect
:
dialect
,
dialect
:
dialect
,
onComplete
:
function
(
sequelize
)
{
onComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
this
.
sequelize
=
sequelize
done
()
done
()
}.
bind
(
this
)
}.
bind
(
this
)
})
})
})
//- before
})
//- before
var
checks
=
{
var
checks
=
{
is
:
{
is
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"0"
,
fail
:
"0"
,
pass
:
"a"
pass
:
"a"
},
},
not
:
{
not
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"a"
,
fail
:
"a"
,
pass
:
"0"
pass
:
"0"
},
},
isEmail
:
{
isEmail
:
{
fail
:
"a"
,
fail
:
"a"
,
pass
:
"abc@abc.com"
pass
:
"abc@abc.com"
}
,
isUrl
:
{
fail
:
"abc"
,
pass
:
"http://abc.com"
}
,
isIP
:
{
fail
:
"abc"
,
pass
:
"129.89.23.1"
}
,
isAlpha
:
{
fail
:
"012"
,
pass
:
"abc"
}
,
isAlphanumeric
:
{
fail
:
"_abc019"
,
pass
:
"abc019"
}
,
isNumeric
:
{
fail
:
"abc"
,
pass
:
"019"
}
,
isInt
:
{
fail
:
"9.2"
,
pass
:
"-9"
}
,
isLowercase
:
{
fail
:
"AB"
,
pass
:
"ab"
}
,
isUppercase
:
{
fail
:
"ab"
,
pass
:
"AB"
}
,
isDecimal
:
{
fail
:
"a"
,
pass
:
"0.2"
}
,
isFloat
:
{
fail
:
"a"
,
pass
:
"9.2"
}
,
notNull
:
{
fail
:
null
,
pass
:
0
}
,
isNull
:
{
fail
:
0
,
pass
:
null
}
,
notEmpty
:
{
fail
:
" "
,
pass
:
"a"
}
,
equals
:
{
spec
:
{
args
:
"bla bla bla"
},
fail
:
"bla"
,
pass
:
"bla bla bla"
}
,
contains
:
{
spec
:
{
args
:
"bla"
},
fail
:
"la"
,
pass
:
"0bla23"
}
,
notContains
:
{
spec
:
{
args
:
"bla"
},
fail
:
"0bla23"
,
pass
:
"la"
}
,
regex
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"0"
,
pass
:
"a"
}
,
notRegex
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"a"
,
pass
:
"0"
}
,
len
:
{
spec
:
{
args
:
[
2
,
4
]
},
fail
:
[
"1"
,
"12345"
],
pass
:
[
"12"
,
"123"
,
"1234"
],
raw
:
true
}
,
isUUID
:
{
spec
:
{
args
:
4
},
fail
:
"f47ac10b-58cc-3372-a567-0e02b2c3d479"
,
pass
:
"f47ac10b-58cc-4372-a567-0e02b2c3d479"
}
,
isDate
:
{
fail
:
"not a date"
,
pass
:
"2011-02-04"
}
,
isAfter
:
{
spec
:
{
args
:
"2011-11-05"
},
fail
:
"2011-11-04"
,
pass
:
"2011-11-05"
}
,
isBefore
:
{
spec
:
{
args
:
"2011-11-05"
},
fail
:
"2011-11-06"
,
pass
:
"2011-11-05"
}
,
isIn
:
{
spec
:
{
args
:
"abcdefghijk"
},
fail
:
"ghik"
,
pass
:
"ghij"
}
,
notIn
:
{
spec
:
{
args
:
"abcdefghijk"
},
fail
:
"ghij"
,
pass
:
"ghik"
}
,
max
:
{
spec
:
{
args
:
23
},
fail
:
"24"
,
pass
:
"23"
}
,
min
:
{
spec
:
{
args
:
23
},
fail
:
"22"
,
pass
:
"23"
}
,
isArray
:
{
fail
:
22
,
pass
:
[
22
]
}
,
isCreditCard
:
{
fail
:
"401288888888188f"
,
pass
:
"4012888888881881"
}
}
}
,
isUrl
:
{
fail
:
"abc"
,
pass
:
"http://abc.com"
}
,
isIP
:
{
fail
:
"abc"
,
pass
:
"129.89.23.1"
}
,
isAlpha
:
{
fail
:
"012"
,
pass
:
"abc"
}
,
isAlphanumeric
:
{
fail
:
"_abc019"
,
pass
:
"abc019"
}
,
isNumeric
:
{
fail
:
"abc"
,
pass
:
"019"
}
,
isInt
:
{
fail
:
"9.2"
,
pass
:
"-9"
}
,
isLowercase
:
{
fail
:
"AB"
,
pass
:
"ab"
}
,
isUppercase
:
{
fail
:
"ab"
,
pass
:
"AB"
}
,
isDecimal
:
{
fail
:
"a"
,
pass
:
"0.2"
}
,
isFloat
:
{
fail
:
"a"
,
pass
:
"9.2"
}
,
notNull
:
{
fail
:
null
,
pass
:
0
}
,
isNull
:
{
fail
:
0
,
pass
:
null
}
,
notEmpty
:
{
fail
:
" "
,
pass
:
"a"
}
,
equals
:
{
spec
:
{
args
:
"bla bla bla"
},
fail
:
"bla"
,
pass
:
"bla bla bla"
}
,
contains
:
{
spec
:
{
args
:
"bla"
},
fail
:
"la"
,
pass
:
"0bla23"
}
,
notContains
:
{
spec
:
{
args
:
"bla"
},
fail
:
"0bla23"
,
pass
:
"la"
}
,
regex
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"0"
,
pass
:
"a"
}
,
notRegex
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"a"
,
pass
:
"0"
}
,
len
:
{
spec
:
{
args
:
[
2
,
4
]
},
fail
:
[
"1"
,
"12345"
],
pass
:
[
"12"
,
"123"
,
"1234"
],
raw
:
true
}
,
isUUID
:
{
spec
:
{
args
:
4
},
fail
:
"f47ac10b-58cc-3372-a567-0e02b2c3d479"
,
pass
:
"f47ac10b-58cc-4372-a567-0e02b2c3d479"
}
,
isDate
:
{
fail
:
"not a date"
,
pass
:
"2011-02-04"
}
,
isAfter
:
{
spec
:
{
args
:
"2011-11-05"
},
fail
:
"2011-11-04"
,
pass
:
"2011-11-05"
}
,
isBefore
:
{
spec
:
{
args
:
"2011-11-05"
},
fail
:
"2011-11-06"
,
pass
:
"2011-11-05"
}
,
isIn
:
{
spec
:
{
args
:
"abcdefghijk"
},
fail
:
"ghik"
,
pass
:
"ghij"
}
,
notIn
:
{
spec
:
{
args
:
"abcdefghijk"
},
fail
:
"ghij"
,
pass
:
"ghik"
}
,
max
:
{
spec
:
{
args
:
23
},
fail
:
"24"
,
pass
:
"23"
}
,
min
:
{
spec
:
{
args
:
23
},
fail
:
"22"
,
pass
:
"23"
}
,
isArray
:
{
fail
:
22
,
pass
:
[
22
]
}
,
isCreditCard
:
{
fail
:
"401288888888188f"
,
pass
:
"4012888888881881"
}
}
for
(
var
validator
in
checks
)
{
for
(
var
validator
in
checks
)
{
if
(
checks
.
hasOwnProperty
(
validator
))
{
if
(
checks
.
hasOwnProperty
(
validator
))
{
var
validatorDetails
=
checks
[
validator
]
var
validatorDetails
=
checks
[
validator
]
if
(
!
validatorDetails
.
hasOwnProperty
(
"raw"
))
{
validatorDetails
.
fail
=
[
validatorDetails
.
fail
]
validatorDetails
.
pass
=
[
validatorDetails
.
pass
]
}
//////////////////////////
// test the error cases //
//////////////////////////
for
(
var
i
=
0
;
i
<
validatorDetails
.
fail
.
length
;
i
++
)
{
var
failingValue
=
validatorDetails
.
fail
[
i
]
it
(
'correctly specifies an instance as invalid using a value of "'
+
failingValue
+
'" for the validation "'
+
validator
+
'"'
,
function
()
{
if
(
!
validatorDetails
.
hasOwnProperty
(
"raw"
))
{
var
validations
=
{}
validatorDetails
.
fail
=
[
validatorDetails
.
fail
]
,
message
=
validator
+
"("
+
failingValue
+
")"
validatorDetails
.
pass
=
[
validatorDetails
.
pass
]
}
if
(
validatorDetails
.
hasOwnProperty
(
'spec'
))
{
//////////////////////////
validations
[
validator
]
=
validatorDetails
.
spec
// test the error cases //
}
else
{
//////////////////////////
validations
[
validator
]
=
{}
for
(
var
i
=
0
;
i
<
validatorDetails
.
fail
.
length
;
i
++
)
{
}
var
failingValue
=
validatorDetails
.
fail
[
i
]
validations
[
validator
].
msg
=
message
it
(
'correctly specifies an instance as invalid using a value of "'
+
failingValue
+
'" for the validation "'
+
validator
+
'"'
,
function
()
{
var
validations
=
{}
,
message
=
validator
+
"("
+
failingValue
+
")"
var
UserFail
=
this
.
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
if
(
validatorDetails
.
hasOwnProperty
(
'spec'
))
{
name
:
{
validations
[
validator
]
=
validatorDetails
.
spec
type
:
Sequelize
.
STRING
,
}
else
{
validate
:
validations
validations
[
validator
]
=
{}
}
}
})
var
failingUser
=
UserFail
.
build
({
name
:
failingValue
})
validations
[
validator
].
msg
=
message
,
errors
=
failingUser
.
validate
()
expect
(
errors
).
not
.
toBeNull
()
var
UserFail
=
this
.
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
expect
(
errors
).
toEqual
({
name
:
[
message
]
})
name
:
{
type
:
Sequelize
.
STRING
,
validate
:
validations
}
})
})
}
////////////////////////////
var
failingUser
=
UserFail
.
build
({
name
:
failingValue
})
// test the success cases //
,
errors
=
failingUser
.
validate
()
////////////////////////////
for
(
var
j
=
0
;
j
<
validatorDetails
.
pass
.
length
;
j
++
)
{
var
succeedingValue
=
validatorDetails
.
pass
[
j
]
it
(
'correctly specifies an instance as valid using a value of "'
+
succeedingValue
+
'" for the validation "'
+
validator
+
'"'
,
function
()
{
expect
(
errors
).
not
.
toBeNull
()
var
validations
=
{}
expect
(
errors
).
toEqual
({
name
:
[
message
]
})
})
}
if
(
validatorDetails
.
hasOwnProperty
(
'spec'
))
{
////////////////////////////
validations
[
validator
]
=
validatorDetails
.
spec
// test the success cases //
}
else
{
////////////////////////////
validations
[
validator
]
=
{}
for
(
var
j
=
0
;
j
<
validatorDetails
.
pass
.
length
;
j
++
)
{
}
var
succeedingValue
=
validatorDetails
.
pass
[
j
]
it
(
'correctly specifies an instance as valid using a value of "'
+
succeedingValue
+
'" for the validation "'
+
validator
+
'"'
,
function
()
{
var
validations
=
{}
validations
[
validator
].
msg
=
validator
+
"("
+
succeedingValue
+
")"
if
(
validatorDetails
.
hasOwnProperty
(
'spec'
))
{
validations
[
validator
]
=
validatorDetails
.
spec
}
else
{
validations
[
validator
]
=
{}
}
var
UserSuccess
=
this
.
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
validations
[
validator
].
msg
=
validator
+
"("
+
succeedingValue
+
")"
name
:
{
type
:
Sequelize
.
STRING
,
validate
:
validations
}
})
var
successfulUser
=
UserSuccess
.
build
({
name
:
succeedingValue
})
var
UserSuccess
=
this
.
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
expect
(
successfulUser
.
validate
()).
toBeNull
()
name
:
{
type
:
Sequelize
.
STRING
,
validate
:
validations
}
})
})
}
var
successfulUser
=
UserSuccess
.
build
({
name
:
succeedingValue
})
expect
(
successfulUser
.
validate
()).
toBeNull
()
})
}
}
}
}
}
it
(
'correctly validates using custom validation methods'
,
function
()
{
it
(
'correctly validates using custom validation methods'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
var
User
=
this
.
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
name
:
{
name
:
{
type
:
Sequelize
.
STRING
,
type
:
Sequelize
.
STRING
,
validate
:
{
validate
:
{
customFn
:
function
(
val
)
{
customFn
:
function
(
val
)
{
if
(
val
!==
"2"
)
{
if
(
val
!==
"2"
)
{
throw
new
Error
(
"name should equal '2'"
)
throw
new
Error
(
"name should equal '2'"
)
}
}
}
}
}
}
}
})
}
})
var
failingUser
=
User
.
build
({
name
:
"3"
})
var
failingUser
=
User
.
build
({
name
:
"3"
})
,
errors
=
failingUser
.
validate
()
,
errors
=
failingUser
.
validate
()
expect
(
errors
).
not
.
toBeNull
(
null
)
expect
(
errors
).
not
.
toBeNull
(
null
)
expect
(
errors
).
toEqual
({
name
:
[
"name should equal '2'"
]
})
expect
(
errors
).
toEqual
({
name
:
[
"name should equal '2'"
]
})
var
successfulUser
=
User
.
build
({
name
:
"2"
})
var
successfulUser
=
User
.
build
({
name
:
"2"
})
expect
(
successfulUser
.
validate
()).
toBeNull
()
expect
(
successfulUser
.
validate
()).
toBeNull
()
})
})
})
})
})
})
})
spec/query-chainer.spec.js
View file @
a59c409
...
@@ -2,13 +2,14 @@ if(typeof require === 'function') {
...
@@ -2,13 +2,14 @@ if(typeof require === 'function') {
const
buster
=
require
(
"buster"
)
const
buster
=
require
(
"buster"
)
,
QueryChainer
=
require
(
"../lib/query-chainer"
)
,
QueryChainer
=
require
(
"../lib/query-chainer"
)
,
CustomEventEmitter
=
require
(
"../lib/emitters/custom-event-emitter"
)
,
CustomEventEmitter
=
require
(
"../lib/emitters/custom-event-emitter"
)
,
Helpers
=
require
(
'./buster-helpers'
)
,
dialect
=
Helpers
.
getTestDialect
()
}
}
buster
.
spec
.
expose
()
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
1000
buster
.
testRunner
.
timeout
=
1000
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] QueryChainer"
,
function
()
{
describe
(
'QueryChainer'
,
function
()
{
before
(
function
()
{
before
(
function
()
{
this
.
queryChainer
=
new
QueryChainer
()
this
.
queryChainer
=
new
QueryChainer
()
})
})
...
...
spec/sequelize.spec.js
View file @
a59c409
if
(
typeof
require
===
'function'
)
{
if
(
typeof
require
===
'function'
)
{
const
buster
=
require
(
"buster"
)
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'./buster-helpers'
)
,
Helpers
=
require
(
'./buster-helpers'
)
,
dialect
=
Helpers
.
getTestDialect
()
}
}
buster
.
spec
.
expose
()
buster
.
spec
.
expose
()
describe
(
'Sequelize'
,
function
()
{
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] Sequelize"
,
function
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
Helpers
.
initTests
({
beforeComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
}.
bind
(
this
),
beforeComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
}.
bind
(
this
),
...
@@ -44,7 +46,7 @@ describe('Sequelize', function() {
...
@@ -44,7 +46,7 @@ describe('Sequelize', function() {
})
})
})
})
it
(
'executes a query if only the sql is passed'
,
function
(
done
)
{
it
(
'
//
executes a query if only the sql is passed'
,
function
(
done
)
{
this
.
sequelize
.
query
(
this
.
insertQuery
).
success
(
function
(
result
)
{
this
.
sequelize
.
query
(
this
.
insertQuery
).
success
(
function
(
result
)
{
expect
(
result
).
toBeNull
()
expect
(
result
).
toBeNull
()
done
()
done
()
...
...
spec/sqlite/dao.spec.js
View file @
a59c409
if
(
typeof
require
===
'function'
)
{
if
(
typeof
require
===
'function'
)
{
const
buster
=
require
(
"buster"
)
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
dialect
=
Helpers
.
getTestDialect
()
}
}
buster
.
spec
.
expose
()
buster
.
spec
.
expose
()
describe
(
'DAO@sqlite'
,
function
()
{
if
(
dialect
===
'sqlite'
)
{
before
(
function
(
done
)
{
describe
(
'[SQLITE] DAO'
,
function
()
{
var
self
=
this
before
(
function
(
done
)
{
var
self
=
this
Helpers
.
initTests
({
Helpers
.
initTests
({
dialect
:
'sqlite'
,
dialect
:
'sqlite'
,
beforeComplete
:
function
(
sequelize
,
DataTypes
)
{
beforeComplete
:
function
(
sequelize
,
DataTypes
)
{
self
.
sequelize
=
sequelize
self
.
sequelize
=
sequelize
self
.
User
=
sequelize
.
define
(
'User'
,
{
self
.
User
=
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
username
:
DataTypes
.
STRING
})
})
},
},
onComplete
:
function
(
sequelize
)
{
onComplete
:
function
()
{
self
.
User
.
sync
({
force
:
true
}).
success
(
done
)
self
.
User
.
sync
({
force
:
true
}).
success
(
done
)
}
}
})
})
})
})
describe
(
'findAll'
,
function
()
{
describe
(
'findAll'
,
function
()
{
it
(
"handles dates correctly"
,
function
(
done
)
{
it
(
"handles dates correctly"
,
function
(
done
)
{
var
self
=
this
var
self
=
this
this
.
User
this
.
User
.
create
({
username
:
'user'
,
createdAt
:
new
Date
(
2011
,
04
,
04
)
})
.
create
({
username
:
'user'
,
createdAt
:
new
Date
(
2011
,
04
,
04
)
})
.
success
(
function
(
oldUser
)
{
.
success
(
function
(
oldUser
)
{
self
.
User
self
.
User
.
create
({
username
:
'new user'
})
.
create
({
username
:
'new user'
})
.
success
(
function
(
newUser
)
{
.
success
(
function
(
newUser
)
{
self
.
User
.
findAll
({
self
.
User
.
findAll
({
where
:
[
'createdAt > ?'
,
new
Date
(
2012
,
01
,
01
)]
where
:
[
'createdAt > ?'
,
new
Date
(
2012
,
01
,
01
)]
}).
success
(
function
(
users
)
{
}).
success
(
function
(
users
)
{
expect
(
users
.
length
).
toEqual
(
1
)
expect
(
users
.
length
).
toEqual
(
1
)
done
()
done
()
})
})
})
})
})
})
.
error
(
function
(
err
)
{
.
error
(
function
(
err
)
{
console
.
log
(
err
)
console
.
log
(
err
)
}
)
})
})
})
})
})
})
}
)
}
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