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 #
-
[
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
-
[
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
]
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
]
# v1.5.0 #
-
[
REFACTORING
]
use underscore functions for Utils.isHash (thanks to Mick-Hansen/innofluence)
...
...
package.json
View file @
a59c409
...
...
@@ -48,7 +48,10 @@
"scripts"
:
{
"test"
:
"npm run test-jasmine && npm run test-buster"
,
"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"
},
"bin"
:
{
...
...
spec/associations/belongs-to.spec.js
View file @
a59c409
...
...
@@ -2,45 +2,43 @@ if (typeof require === 'function') {
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
Sequelize
=
require
(
'../../index'
)
,
dialect
s
=
Helpers
.
getSupportedDialects
()
,
dialect
=
Helpers
.
getTestDialect
()
}
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
500
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
'BelongsTo@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
beforeComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
}.
bind
(
this
),
onComplete
:
done
})
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] BelongsTo"
,
function
()
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
beforeComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
}.
bind
(
this
),
onComplete
:
done
})
})
describe
(
'setAssociation'
,
function
()
{
it
(
'clears the association if null is passed'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
describe
(
'setAssociation'
,
function
()
{
it
(
'clears the association if null is passed'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
Task
.
belongsTo
(
User
)
Task
.
belongsTo
(
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUser
(
user
).
success
(
function
()
{
task
.
getUser
().
success
(
function
(
user
)
{
expect
(
user
).
not
.
toEqual
(
null
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUser
(
user
).
success
(
function
()
{
task
.
getUser
().
success
(
function
(
user
)
{
expect
(
user
).
not
.
toEqual
(
null
)
task
.
setUser
(
null
).
success
(
function
()
{
task
.
getUser
().
success
(
function
(
user
)
{
expect
(
user
).
toEqual
(
null
)
done
()
})
task
.
setUser
(
null
).
success
(
function
()
{
task
.
getUser
().
success
(
function
(
user
)
{
expect
(
user
).
toEqual
(
null
)
done
()
})
})
})
})
})
...
...
spec/associations/has-many.spec.js
View file @
a59c409
...
...
@@ -2,163 +2,133 @@ if (typeof require === 'function') {
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
Sequelize
=
require
(
'../../index'
)
,
dialect
s
=
Helpers
.
getSupportedDialects
()
,
dialect
=
Helpers
.
getTestDialect
()
}
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
500
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
'HasMany@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] HasMany"
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
Helpers
.
initTests
({
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
onComplete
:
done
})
Helpers
.
initTests
({
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
onComplete
:
done
})
})
describe
(
'(1:N)'
,
function
()
{
describe
(
'hasSingle'
,
function
()
{
before
(
function
(
done
)
{
this
.
Article
=
this
.
sequelize
.
define
(
'Article'
,
{
'title'
:
Sequelize
.
STRING
})
this
.
Label
=
this
.
sequelize
.
define
(
'Label'
,
{
'text'
:
Sequelize
.
STRING
})
describe
(
'(1:N)'
,
function
()
{
describe
(
'hasSingle'
,
function
()
{
before
(
function
(
done
)
{
this
.
Article
=
this
.
sequelize
.
define
(
'Article'
,
{
'title'
:
Sequelize
.
STRING
})
this
.
Label
=
this
.
sequelize
.
define
(
'Label'
,
{
'text'
:
Sequelize
.
STRING
})
this
.
Article
.
hasMany
(
this
.
Label
)
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
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
([
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
article
.
hasLabel
(
label1
),
article
.
hasLabel
(
label2
)
])
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
article
.
hasLabel
(
label1
),
article
.
hasLabel
(
label2
)
])
chainer
.
run
().
success
(
function
(
_
,
hasLabel1
,
hasLabel2
)
{
expect
(
hasLabel1
).
toBeFalse
()
expect
(
hasLabel2
).
toBeFalse
()
done
()
})
chainer
.
run
().
success
(
function
(
_
,
hasLabel1
,
hasLabel2
)
{
expect
(
hasLabel1
).
toBeFalse
()
expect
(
hasLabel2
).
toBeFalse
()
done
()
})
})
})
it
(
'answers true if the label has been assigned'
,
function
(
done
)
{
var
self
=
this
it
(
'answers true if the label has been assigned'
,
function
(
done
)
{
var
self
=
this
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
])
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
this
.
Article
.
create
({
title
:
'Article'
})
,
this
.
Label
.
create
({
text
:
'Awesomeness'
})
,
this
.
Label
.
create
({
text
:
'Epicness'
})
[
article
,
'addLabel'
,
[
label1
]]
,
[
article
,
'hasLabel'
,
[
label1
]]
,
[
article
,
'hasLabel'
,
[
label2
]]
])
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
[
article
,
'addLabel'
,
[
label1
]],
[
article
,
'hasLabel'
,
[
label1
]],
[
article
,
'hasLabel'
,
[
label2
]]
])
chainer
.
runSerially
().
success
(
function
(
_
,
label1
,
hasLabel1
,
hasLabel2
)
{
expect
(
hasLabel1
).
toBeTrue
()
expect
(
hasLabel2
).
toBeFalse
()
done
()
})
chainer
.
runSerially
().
success
(
function
(
_
,
label1
,
hasLabel1
,
hasLabel2
)
{
expect
(
hasLabel1
).
toBeTrue
()
expect
(
hasLabel2
).
toBeFalse
()
done
()
})
})
})
})
describe
(
'hasAll'
,
function
()
{
before
(
function
(
done
)
{
this
.
Article
=
this
.
sequelize
.
define
(
'Article'
,
{
'title'
:
Sequelize
.
STRING
})
this
.
Label
=
this
.
sequelize
.
define
(
'Label'
,
{
'text'
:
Sequelize
.
STRING
})
this
.
Article
.
hasMany
(
this
.
Label
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
done
)
})
describe
(
'hasAll'
,
function
()
{
before
(
function
(
done
)
{
this
.
Article
=
this
.
sequelize
.
define
(
'Article'
,
{
'title'
:
Sequelize
.
STRING
})
this
.
Label
=
this
.
sequelize
.
define
(
'Label'
,
{
'text'
:
Sequelize
.
STRING
})
it
(
'answers false if only some labels have been assigned'
,
function
(
done
)
{
var
self
=
this
this
.
Article
.
hasMany
(
this
.
Label
)
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
])
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
article
.
addLabel
(
label1
).
success
(
function
()
{
article
.
hasLabels
([
label1
,
label2
]).
success
(
function
(
result
)
{
expect
(
result
).
toBeFalse
()
done
()
})
})
})
})
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
done
)
})
it
(
'answers true if all label
have been assigned'
,
function
(
done
)
{
var
self
=
this
it
(
'answers false if only some labels
have been assigned'
,
function
(
done
)
{
var
self
=
this
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
])
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
this
.
Article
.
create
({
title
:
'Article'
}),
this
.
Label
.
create
({
text
:
'Awesomeness'
}),
this
.
Label
.
create
({
text
:
'Epicness'
})
])
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
article
.
setLabels
([
label1
,
label2
]).
success
(
function
()
{
article
.
hasLabels
([
label1
,
label2
]).
success
(
function
(
result
)
{
expect
(
result
).
toBeTrue
()
done
()
})
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
article
.
addLabel
(
label1
).
success
(
function
()
{
article
.
hasLabels
([
label1
,
label2
]).
success
(
function
(
result
)
{
expect
(
result
).
toBeFalse
()
done
()
})
})
})
})
describe
(
'setAssociations'
,
function
()
{
it
(
"clears associations when passing null to the set-method"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
it
(
'answers true if all label have been assigned'
,
function
(
done
)
{
var
self
=
this
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
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUsers
([
user
]).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
1
)
task
.
setUsers
(
null
).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
0
)
done
()
})
})
})
})
})
chainer
.
run
().
success
(
function
(
results
,
article
,
label1
,
label2
)
{
article
.
setLabels
([
label1
,
label2
]).
success
(
function
()
{
article
.
hasLabels
([
label1
,
label2
]).
success
(
function
(
result
)
{
expect
(
result
).
toBeTrue
()
done
()
})
})
})
})
})
it
(
"clears associations when passing null to the set-method with omitNull set to true"
,
function
(
done
)
{
this
.
sequelize
.
options
.
omitNull
=
true
describe
(
'setAssociations'
,
function
()
{
it
(
"clears associations when passing null to the set-method"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
...
...
@@ -183,138 +153,166 @@ dialects.forEach(function(dialect) {
})
})
})
})
describe
(
"getting assocations with options"
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
;
it
(
"clears associations when passing null to the set-method with omitNull set to true"
,
function
(
done
)
{
this
.
sequelize
.
options
.
omitNull
=
true
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
,
active
:
Sequelize
.
BOOLEAN
})
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
this
.
User
.
hasMany
(
self
.
Task
)
Task
.
hasMany
(
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
()
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
self
.
User
.
create
({
username
:
'John'
}),
self
.
Task
.
create
({
title
:
'Get rich'
,
active
:
true
}),
self
.
Task
.
create
({
title
:
'Die trying'
,
active
:
false
})
]
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUsers
([
user
]).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
1
)
chainer
.
run
().
success
(
function
(
results
,
john
,
task1
,
task2
)
{
john
.
setTasks
([
task1
,
task2
]).
success
(
done
)
task
.
setUsers
(
null
).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
0
)
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
();
})
describe
(
"getting assocations with options"
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
;
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
,
active
:
Sequelize
.
BOOLEAN
})
this
.
User
.
hasMany
(
self
.
Task
)
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
()
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
self
.
User
.
create
({
username
:
'John'
}),
self
.
Task
.
create
({
title
:
'Get rich'
,
active
:
true
}),
self
.
Task
.
create
({
title
:
'Die trying'
,
active
:
false
})
])
chainer
.
run
().
success
(
function
(
results
,
john
,
task1
,
task2
)
{
john
.
setTasks
([
task1
,
task2
]).
success
(
done
)
})
})
})
it
(
"gets all associated objects when no options are passed"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
().
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
2
)
done
();
})
})
})
it
(
"only get objects that fulfill the options"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}
}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
},
limit
:
10
,
order
:
'id DESC'
}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
done
();
})
it
(
"only get objects that fulfill the options"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}
}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
},
limit
:
10
,
order
:
'id DESC'
}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
done
();
})
})
})
})
})
describe
(
'(N:M)'
,
function
()
{
describe
(
"getting assocations with options"
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
;
describe
(
'(N:M)'
,
function
()
{
describe
(
"getting assocations with options"
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
;
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
,
active
:
Sequelize
.
BOOLEAN
})
this
.
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
,
active
:
Sequelize
.
BOOLEAN
})
self
.
User
.
hasMany
(
self
.
Task
)
self
.
Task
.
hasMany
(
self
.
User
)
self
.
User
.
hasMany
(
self
.
Task
)
self
.
Task
.
hasMany
(
self
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
()
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
self
.
User
.
create
({
username
:
'John'
}),
self
.
Task
.
create
({
title
:
'Get rich'
,
active
:
true
}),
self
.
Task
.
create
({
title
:
'Die trying'
,
active
:
false
})
])
this
.
sequelize
.
sync
({
force
:
true
}).
done
(
function
()
{
var
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
([
self
.
User
.
create
({
username
:
'John'
}),
self
.
Task
.
create
({
title
:
'Get rich'
,
active
:
true
}),
self
.
Task
.
create
({
title
:
'Die trying'
,
active
:
false
})
])
chainer
.
run
().
success
(
function
(
results
,
john
,
task1
,
task2
)
{
john
.
setTasks
([
task1
,
task2
]).
success
(
done
)
})
chainer
.
run
().
success
(
function
(
results
,
john
,
task1
,
task2
)
{
john
.
setTasks
([
task1
,
task2
]).
success
(
done
)
})
})
})
it
(
"gets all associated objects when no options are passed"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
().
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
2
)
done
();
})
it
(
"gets all associated objects when no options are passed"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
().
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
2
)
done
();
})
})
})
it
(
"only get objects that fulfill the options"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
}}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
done
();
})
it
(
"only get objects that fulfill the options"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'John'
}}).
success
(
function
(
john
)
{
john
.
getTasks
({
where
:
{
active
:
true
}}).
success
(
function
(
tasks
)
{
expect
(
tasks
.
length
).
toEqual
(
1
)
done
();
})
})
})
})
it
(
"removes the reference id, which was added in the first place"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
it
(
"removes the reference id, which was added in the first place"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
)
expect
(
Task
.
attributes
.
UserId
).
toBeDefined
()
User
.
hasMany
(
Task
)
expect
(
Task
.
attributes
.
UserId
).
toBeDefined
()
Task
.
hasMany
(
User
)
expect
(
Task
.
attributes
.
UserId
).
not
.
toBeDefined
()
})
Task
.
hasMany
(
User
)
expect
(
Task
.
attributes
.
UserId
).
not
.
toBeDefined
()
})
it
(
"adds three items to the query chainer when calling sync"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
it
(
"adds three items to the query chainer when calling sync"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
)
Task
.
hasMany
(
User
)
User
.
hasMany
(
Task
)
Task
.
hasMany
(
User
)
var
add
=
this
.
spy
()
var
add
=
this
.
spy
()
this
.
stub
(
Sequelize
.
Utils
,
'QueryChainer'
).
returns
({
add
:
add
,
run
:
function
(){}
})
this
.
stub
(
Sequelize
.
Utils
,
'QueryChainer'
).
returns
({
add
:
add
,
run
:
function
(){}
})
this
.
sequelize
.
sync
({
force
:
true
})
expect
(
add
).
toHaveBeenCalledThrice
()
})
this
.
sequelize
.
sync
({
force
:
true
})
expect
(
add
).
toHaveBeenCalledThrice
()
})
describe
(
'setAssociations'
,
function
()
{
it
(
"clears associations when passing null to the set-method"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
describe
(
'setAssociations'
,
function
()
{
it
(
"clears associations when passing null to the set-method"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
)
Task
.
hasMany
(
User
)
User
.
hasMany
(
Task
)
Task
.
hasMany
(
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUsers
([
user
]).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
1
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
task
.
setUsers
([
user
]).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
1
)
task
.
setUsers
(
null
).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
0
)
done
()
})
task
.
setUsers
(
null
).
success
(
function
()
{
task
.
getUsers
().
success
(
function
(
_users
)
{
expect
(
_users
.
length
).
toEqual
(
0
)
done
()
})
})
})
...
...
spec/associations/has-one.spec.js
View file @
a59c409
...
...
@@ -2,46 +2,44 @@ if (typeof require === 'function') {
const
buster
=
require
(
"buster"
)
,
Sequelize
=
require
(
"../../index"
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
dialect
s
=
Helpers
.
getSupportedDialects
()
,
dialect
=
Helpers
.
getTestDialect
()
}
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
500
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
'HasOne@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] HasOne"
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
Helpers
.
initTests
({
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
onComplete
:
done
})
Helpers
.
initTests
({
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
)
{
self
.
sequelize
=
sequelize
},
onComplete
:
done
})
})
describe
(
'setAssociation'
,
function
()
{
it
(
'clears the association if null is passed'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
User
.
hasOne
(
Task
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
user
.
setTask
(
task
).
success
(
function
()
{
user
.
getTask
().
success
(
function
(
task
)
{
expect
(
task
).
not
.
toEqual
(
null
)
user
.
setTask
(
null
).
success
(
function
()
{
user
.
getTask
().
success
(
function
(
task
)
{
expect
(
task
).
toEqual
(
null
)
done
()
})
})
describe
(
'setAssociation'
,
function
()
{
it
(
'clears the association if null is passed'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
,
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
User
.
hasOne
(
Task
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
user
.
setTask
(
task
).
success
(
function
()
{
user
.
getTask
().
success
(
function
(
task
)
{
expect
(
task
).
not
.
toEqual
(
null
)
user
.
setTask
(
null
).
success
(
function
()
{
user
.
getTask
().
success
(
function
(
task
)
{
expect
(
task
).
toEqual
(
null
)
done
()
})
})
})
})
})
...
...
spec/associations/mixin.spec.js
View file @
a59c409
...
...
@@ -2,33 +2,31 @@ if (typeof require === 'function') {
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
Sequelize
=
require
(
'../../index'
)
,
dialect
s
=
Helpers
.
getSupportedDialects
()
,
dialect
=
Helpers
.
getTestDialect
()
}
buster
.
spec
.
expose
()
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
'Mixin@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
}.
bind
(
this
),
onComplete
:
done
})
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] Mixin"
,
function
()
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
}.
bind
(
this
),
onComplete
:
done
})
})
describe
(
'getAssociation'
,
function
()
{
it
(
'returns the respective part of the association for 1:1 associations'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{})
describe
(
'getAssociation'
,
function
()
{
it
(
'returns the respective part of the association for 1:1 associations'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{})
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{})
User
.
hasOne
(
Task
)
Task
.
belongsTo
(
User
)
User
.
hasOne
(
Task
)
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') {
const
buster
=
require
(
"buster"
)
,
Sequelize
=
require
(
"../index"
)
,
Helpers
=
require
(
'./buster-helpers'
)
,
dialect
s
=
Helpers
.
getSupportedDialects
()
,
dialect
=
Helpers
.
getTestDialect
()
}
buster
.
spec
.
expose
()
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
'DAOFactory@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
,
DataTypes
)
{
this
.
sequelize
=
sequelize
this
.
User
=
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
,
secretValue
:
DataTypes
.
STRING
,
data
:
DataTypes
.
STRING
})
}.
bind
(
this
),
onComplete
:
function
(
sequelize
)
{
this
.
User
.
sync
({
force
:
true
}).
success
(
done
)
}.
bind
(
this
)
})
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] DAOFactory"
,
function
()
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
,
DataTypes
)
{
this
.
sequelize
=
sequelize
this
.
User
=
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
,
secretValue
:
DataTypes
.
STRING
,
data
:
DataTypes
.
STRING
})
}.
bind
(
this
),
onComplete
:
function
()
{
this
.
User
.
sync
({
force
:
true
}).
success
(
done
)
}.
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 passed dao name as tablename if freezeTableName"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'FrozenUser'
,
{},
{
freezeTableName
:
true
})
expect
(
User
.
tableName
).
toEqual
(
'FrozenUser'
)
})
it
(
"uses the pluralized dao name as tablename unless freezeTableName"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'SuperUser'
,
{},
{
freezeTableName
:
false
})
expect
(
User
.
tableName
).
toEqual
(
'SuperUsers'
)
})
it
(
"uses the pluralized dao name as tablename unless freezeTableName"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'SuperUser'
,
{},
{
freezeTableName
:
false
})
expect
(
User
.
tableName
).
toEqual
(
'SuperUsers'
)
it
(
"attaches class and instance methods"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'UserWithClassAndInstanceMethods'
,
{},
{
classMethods
:
{
doSmth
:
function
(){
return
1
}
},
instanceMethods
:
{
makeItSo
:
function
(){
return
2
}}
})
it
(
"attaches class and instance methods"
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'UserWithClassAndInstanceMethods'
,
{},
{
classMethods
:
{
doSmth
:
function
(){
return
1
}
},
instanceMethods
:
{
makeItSo
:
function
(){
return
2
}}
})
expect
(
User
.
doSmth
).
toBeDefined
()
expect
(
User
.
doSmth
()).
toEqual
(
1
)
expect
(
User
.
makeItSo
).
not
.
toBeDefined
()
expect
(
User
.
doSmth
).
toBeDefined
()
expect
(
User
.
doSmth
()).
toEqual
(
1
)
expect
(
User
.
makeItSo
).
not
.
toBeDefined
()
expect
(
User
.
build
().
doSmth
).
not
.
toBeDefined
()
expect
(
User
.
build
().
makeItSo
).
toBeDefined
()
expect
(
User
.
build
().
makeItSo
()).
toEqual
(
2
)
})
expect
(
User
.
build
().
doSmth
).
not
.
toBeDefined
()
expect
(
User
.
build
().
makeItSo
).
toBeDefined
()
expect
(
User
.
build
().
makeItSo
()).
toEqual
(
2
)
})
it
(
"throws an error if 2 autoIncrements are passed"
,
function
()
{
try
{
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
()
{
try
{
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.'
)
}
describe
(
'build'
,
function
()
{
it
(
"doesn't create database entries"
,
function
(
done
)
{
this
.
User
.
build
({
username
:
'John Wayne'
})
this
.
User
.
all
().
success
(
function
(
users
)
{
expect
(
users
.
length
).
toEqual
(
0
)
done
()
})
})
describe
(
'build'
,
function
()
{
it
(
"doesn't create database entries"
,
function
(
done
)
{
this
.
User
.
build
({
username
:
'John Wayne'
})
this
.
User
.
all
().
success
(
function
(
users
)
{
expect
(
users
.
length
).
toEqual
(
0
)
done
()
})
it
(
"fills the objects with default values"
,
function
()
{
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
{
type
:
Sequelize
.
STRING
,
defaultValue
:
'a task!'
},
foo
:
{
type
:
Sequelize
.
INTEGER
,
defaultValue
:
2
},
bar
:
{
type
:
Sequelize
.
DATE
},
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
()
{
var
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
{
type
:
Sequelize
.
STRING
,
defaultValue
:
'a task!'
},
foo
:
{
type
:
Sequelize
.
INTEGER
,
defaultValue
:
2
},
bar
:
{
type
:
Sequelize
.
DATE
},
foobar
:
{
type
:
Sequelize
.
TEXT
,
defaultValue
:
'asd'
},
flag
:
{
type
:
Sequelize
.
BOOLEAN
,
defaultValue
:
false
}
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
error
(
function
(
err
)
{
expect
(
err
).
toBeDefined
()
Helpers
.
checkMatchForDialects
(
dialect
,
err
.
message
,
{
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
()
{
var
user
=
this
.
User
.
build
({
username
:
'John Wayne'
})
expect
(
user
.
selectedValues
).
toEqual
({
username
:
'John Wayne'
})
it
(
"raises an error if created object breaks definition contraints"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithNonNullSmth'
,
{
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
})
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
}
})
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
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
success
(
function
()
{
User
.
create
({
username
:
'foo'
}).
error
(
function
(
err
)
{
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.*/
,
postgres
:
/.*duplicate
\
key
\
value
.*/
mysql
:
"Duplicate entry 'foo' for key 'username'"
,
postgres
:
/.*duplicate
key value violates unique constraint
.*/
})
done
()
...
...
@@ -120,646 +151,629 @@ dialects.forEach(function(dialect) {
})
})
})
})
it
(
"raises an error if created object breaks definition contraints"
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithNonNullSmth'
,
{
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
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
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithAutoIncrementField'
,
{
userid
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
,
allowNull
:
false
}
})
it
(
'sets auto increment fields'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithAutoIncrementField'
,
{
userid
:
{
type
:
Sequelize
.
INTEGER
,
autoIncrement
:
true
,
primaryKey
:
true
,
allowNull
:
false
}
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
expect
(
user
.
userid
).
toEqual
(
1
)
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
expect
(
user
.
userid
).
toEqual
(
1
)
User
.
create
({}).
on
(
'success'
,
function
(
user
)
{
expect
(
user
.
userid
).
toEqual
(
2
)
done
()
})
expect
(
user
.
userid
).
toEqual
(
2
)
done
()
})
})
})
})
it
(
'allows the usage of options as attribute'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithNameAndOptions'
,
{
name
:
Sequelize
.
STRING
,
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 the usage of options as attribute'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithNameAndOptions'
,
{
name
:
Sequelize
.
STRING
,
options
:
Sequelize
.
TEXT
})
it
(
'allows sql logging'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithUniqueNameAndNonNullSmth'
,
{
name
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
name
:
'Fluffy Bunny'
,
smth
:
'else'
})
.
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"INSERT"
)).
toBeGreaterThan
(
-
1
)
done
()
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
name
:
'John Doe'
,
options
:
options
})
.
success
(
function
(
user
)
{
expect
(
user
.
options
).
toEqual
(
options
)
done
()
})
})
})
it
(
'should only store the values passed in the witelist'
,
function
(
done
)
{
var
self
=
this
,
data
=
{
username
:
'Peter'
,
secretValue
:
'42'
}
it
(
'allows sql logging'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithUniqueNameAndNonNullSmth'
,
{
name
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
smth
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
}
})
this
.
User
.
create
(
data
,
[
'username'
]).
success
(
function
(
user
)
{
self
.
User
.
find
(
user
.
id
).
success
(
function
(
_user
)
{
expect
(
_user
.
username
).
toEqual
(
data
.
username
)
expect
(
_user
.
secretValue
).
not
.
toEqual
(
data
.
secretValue
)
expect
(
_user
.
secretValue
).
toEqual
(
null
)
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
name
:
'Fluffy Bunny'
,
smth
:
'else'
})
.
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"INSERT"
)).
toBeGreaterThan
(
-
1
)
done
()
})
})
})
})
it
(
'should store all values if no whitelist is specified
'
,
function
(
done
)
{
var
self
=
this
,
data
=
{
username
:
'Peter'
,
secretValue
:
'42'
}
it
(
'should only store the values passed in the witelist
'
,
function
(
done
)
{
var
self
=
this
,
data
=
{
username
:
'Peter'
,
secretValue
:
'42'
}
this
.
User
.
create
(
data
).
success
(
function
(
user
)
{
self
.
User
.
find
(
user
.
id
).
success
(
function
(
_user
)
{
expect
(
_user
.
username
).
toEqual
(
data
.
username
)
expect
(
_user
.
secretValue
)
.
toEqual
(
data
.
secretValue
)
done
(
)
}
)
this
.
User
.
create
(
data
,
[
'username'
]
).
success
(
function
(
user
)
{
self
.
User
.
find
(
user
.
id
).
success
(
function
(
_user
)
{
expect
(
_user
.
username
).
toEqual
(
data
.
username
)
expect
(
_user
.
secretValue
).
not
.
toEqual
(
data
.
secretValue
)
expect
(
_user
.
secretValue
).
toEqual
(
null
)
done
(
)
})
})
})
it
(
'saves data with single quote'
,
function
(
done
)
{
var
quote
=
"single'quote"
,
self
=
this
this
.
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'memory single quote'
)
it
(
'should store all values if no whitelist is specified'
,
function
(
done
)
{
var
self
=
this
,
data
=
{
username
:
'Peter'
,
secretValue
:
'42'
}
self
.
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'SQL single quote'
)
done
()
})
this
.
User
.
create
(
data
).
success
(
function
(
user
)
{
self
.
User
.
find
(
user
.
id
).
success
(
function
(
_user
)
{
expect
(
_user
.
username
).
toEqual
(
data
.
username
)
expect
(
_user
.
secretValue
).
toEqual
(
data
.
secretValue
)
done
()
})
})
})
it
(
'saves data with doub
le quote'
,
function
(
done
)
{
var
quote
=
'double"quote'
,
self
=
this
it
(
'saves data with sing
le quote'
,
function
(
done
)
{
var
quote
=
"single'quote"
,
self
=
this
this
.
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'memory doub
le quote'
)
this
.
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'memory sing
le quote'
)
self
.
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'SQL double quote'
)
done
()
})
self
.
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'SQL single quote'
)
done
()
})
})
})
it
(
'saves stringified JSON data
'
,
function
(
done
)
{
var
json
=
JSON
.
stringify
({
key
:
'value'
})
,
self
=
this
it
(
'saves data with double quote
'
,
function
(
done
)
{
var
quote
=
'double"quote'
,
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
(
)
}
)
this
.
User
.
create
({
data
:
quote
}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'memory double quote
'
)
self
.
User
.
find
({
where
:
{
id
:
user
.
id
}}).
success
(
function
(
user
)
{
expect
(
user
.
data
).
toEqual
(
quote
,
'SQL double quote'
)
done
(
)
})
})
})
it
(
'stores the current date in createdAt'
,
function
(
done
)
{
this
.
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
expect
(
parseInt
(
+
user
.
createdAt
/
5000
)).
toEqual
(
parseInt
(
+
new
Date
()
/
5000
))
it
(
'saves stringified JSON data'
,
function
(
done
)
{
var
json
=
JSON
.
stringify
({
key
:
'value'
})
,
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
()
})
})
})
describe
(
'find'
,
function
find
()
{
before
(
function
(
done
)
{
this
.
User
.
create
({
username
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
user
=
user
done
()
}.
bind
(
this
))
it
(
'stores the current date in createdAt'
,
function
(
done
)
{
this
.
User
.
create
({
username
:
'foo'
}).
success
(
function
(
user
)
{
expect
(
parseInt
(
+
user
.
createdAt
/
5000
)).
toEqual
(
parseInt
(
+
new
Date
()
/
5000
))
done
()
})
})
})
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
))
describe
(
'find'
,
function
find
()
{
before
(
function
(
done
)
{
this
.
User
.
create
({
username
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
user
=
user
done
()
}.
bind
(
this
))
})
it
(
'returns a single dao'
,
function
(
done
)
{
this
.
User
.
find
(
this
.
user
.
id
).
success
(
function
(
user
)
{
expect
(
Array
.
isArray
(
user
)).
toBeFalsy
()
expect
(
user
.
id
).
toEqual
(
this
.
user
.
id
)
expect
(
user
.
id
).
toEqual
(
1
)
done
()
}.
bind
(
this
))
})
it
(
"should make aliased attributes available"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
id
:
1
},
attributes
:
[
'id'
,
[
'username'
,
'name'
]]
}).
success
(
function
(
user
)
{
expect
(
user
.
name
).
toEqual
(
'barfooz'
)
done
()
})
})
it
(
"should make aliased attributes available"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
id
:
1
},
attributes
:
[
'id'
,
[
'username'
,
'name'
]]
}).
success
(
function
(
user
)
{
expect
(
user
.
name
).
toEqual
(
'barfooz'
)
done
()
})
it
(
'finds a specific user via where option'
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'barfooz'
}
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'barfooz'
)
done
()
})
})
it
(
'finds a specific user via where option'
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'barfooz'
}
}).
success
(
function
(
user
)
{
expect
(
user
.
username
).
toEqual
(
'barfooz'
)
done
()
})
it
(
"doesn't find a user if conditions are not matching"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'foo'
}
}).
success
(
function
(
user
)
{
expect
(
user
).
toBeNull
()
done
()
})
})
it
(
"doesn't find a user if conditions are not matching"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'foo'
}
}).
success
(
function
(
user
)
{
expect
(
user
).
toBeNull
()
it
(
'allows sql logging'
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'foo'
}
})
.
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
done
()
})
})
it
(
'ignores passed limit option'
,
function
(
done
)
{
this
.
User
.
find
({
limit
:
10
}).
success
(
function
(
user
)
{
// it returns an object instead of an array
expect
(
Array
.
isArray
(
user
)).
toBeFalsy
()
expect
(
user
.
hasOwnProperty
(
'username'
)).
toBeTruthy
()
done
()
})
})
it
(
'allows sql logging'
,
function
(
done
)
{
this
.
User
.
find
({
where
:
{
username
:
'foo'
}
})
.
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
it
(
'finds entries via primary keys'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithPrimaryKey'
,
{
identifier
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
},
name
:
Sequelize
.
STRING
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
identifier
:
'an identifier'
,
name
:
'John'
}).
success
(
function
(
u
)
{
expect
(
u
.
id
).
not
.
toBeDefined
()
User
.
find
(
'an identifier'
).
success
(
function
(
u2
)
{
expect
(
u2
.
identifier
).
toEqual
(
'an identifier'
)
expect
(
u2
.
name
).
toEqual
(
'John'
)
done
()
})
})
})
})
it
(
'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
()
it
(
'//returns the selected fields as instance.selectedValues'
,
function
(
done
)
{
this
.
User
.
create
({
username
:
'JohnXOXOXO'
}).
success
(
function
()
{
this
.
User
.
find
({
where
:
{
username
:
'JohnXOXOXO'
},
select
:
[
'username'
]
}).
success
(
function
(
user
)
{
expect
(
user
.
selectedValues
).
toEqual
({
username
:
'JohnXOXOXO'
})
done
()
})
})
}.
bind
(
this
))
})
it
(
'finds entries via primary keys'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'UserWithPrimaryKey'
,
{
identifier
:
{
type
:
Sequelize
.
STRING
,
primaryKey
:
true
},
nam
e
:
Sequelize
.
STRING
describe
(
'association fetching'
,
function
(
)
{
before
(
function
()
{
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
titl
e
:
Sequelize
.
STRING
})
User
.
sync
({
force
:
true
}).
success
(
function
()
{
User
.
create
({
identifier
:
'an identifier'
,
name
:
'John'
}).
success
(
function
(
u
)
{
expect
(
u
.
id
).
not
.
toBeDefined
()
User
.
find
(
'an identifier'
).
success
(
function
(
u2
)
{
expect
(
u2
.
identifier
).
toEqual
(
'an identifier'
)
expect
(
u2
.
name
).
toEqual
(
'John'
)
done
()
})
})
this
.
User
=
this
.
sequelize
.
define
(
'UserWithName'
,
{
name
:
Sequelize
.
STRING
})
})
describe
(
'association fetching'
,
function
()
{
before
(
function
()
{
this
.
Task
=
this
.
sequelize
.
define
(
'Task'
,
{
title
:
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
.
User
=
this
.
sequelize
.
define
(
'UserWithName'
,
{
name
:
Sequelize
.
STRING
})
})
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
user
.
setTask
(
task
).
success
(
function
()
{
this
.
User
.
find
({
where
:
{
'UserWithNames.id'
:
1
},
include
:
[
'Task'
]
}).
success
(
function
(
user
)
{
expect
(
user
.
task
).
toBeDefined
()
expect
(
user
.
task
.
id
).
toEqual
(
task
.
id
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
it
(
'fetches associated objects for 1:1 associations (2nd direction)'
,
function
(
done
)
{
this
.
User
.
hasOne
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
user
.
setTask
(
task
).
success
(
function
()
{
this
.
Task
.
find
({
where
:
{
'Tasks.id'
:
1
},
include
:
[
'UserWithName'
]
}).
success
(
function
(
task
)
{
expect
(
task
.
userWithName
).
toBeDefined
()
expect
(
task
.
userWithName
.
id
).
toEqual
(
user
.
id
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
it
(
'fetches associated objects for 1:1
associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasOne
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
it
(
'fetches associated objects for 1:N
associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
user
.
setTask
(
task
).
success
(
function
()
{
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
.
task
).
toBeDefined
()
expect
(
user
.
task
.
id
).
toEqual
(
task
.
id
)
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
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
}.
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
)
it
(
'fetches associated objects for 1:N
associations (2nd direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
user
.
setTask
(
task
).
success
(
function
()
{
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
.
id
).
toEqual
(
user
.
id
)
expect
(
task
.
userWithName
.
name
).
toEqual
(
user
.
name
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
it
(
'fetches associated objects for 1:N associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
User
.
find
({
where
:
{
'UserWithNames.id'
:
1
},
include
:
[
'Task'
]
}).
success
(
function
(
user
)
{
expect
(
user
.
tasks
).
toBeDefined
()
expect
(
user
.
tasks
.
map
(
function
(
t
)
{
return
t
.
id
})
).
toEqual
(
[
task1
.
id
,
task2
.
id
]
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
it
(
'fetches associated objects for N:M associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
hasMany
(
this
.
User
)
it
(
'fetches associated objects for 1:N associations (2nd direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
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
})
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
it
(
'fetches associated objects for N:M associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
hasMany
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
User
.
find
({
where
:
{
'UserWithNames.id'
:
user1
.
id
},
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
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
User
.
find
({
where
:
{
'UserWithNames.id'
:
user1
.
id
},
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
})
}.
bind
(
this
))
//- User.create
}.
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
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
hasMany
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
Task
.
find
({
where
:
{
'Tasks.id'
:
task1
.
id
},
include
:
[
'UserWithName'
]
}).
success
(
function
(
task
)
{
expect
(
task
.
userWithNames
).
toBeDefined
()
expect
(
task
.
userWithNames
.
map
(
function
(
u
)
{
return
u
.
id
})
).
toEqual
(
[
user1
.
id
]
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
Task
.
find
({
where
:
{
'Tasks.id'
:
task1
.
id
},
include
:
[
'UserWithName'
]
}).
success
(
function
(
task
)
{
expect
(
task
.
userWithNames
).
toBeDefined
()
expect
(
task
.
userWithNames
.
map
(
function
(
u
)
{
return
u
.
id
})
).
toEqual
(
[
user1
.
id
]
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
}.
bind
(
this
))
//- User.create
}.
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'
,
{
name
:
Sequelize
.
STRING
})
})
//- 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'
,
{
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
)
{
this
.
User
.
hasOne
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
it
(
'fetches associated objects for 1:N
associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
user
.
setTask
(
task
).
success
(
function
()
{
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
].
task
).
toBeDefined
()
expect
(
users
[
0
].
task
.
id
).
toEqual
(
task
.
id
)
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
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
}.
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
)
it
(
'fetches associated objects for 1:N
associations (2nd direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task'
}).
success
(
function
(
task
)
{
user
.
setTask
(
task
).
success
(
function
()
{
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
.
id
).
toEqual
(
user
.
id
)
expect
(
tasks
[
0
].
userWithName
.
name
).
toEqual
(
user
.
name
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
it
(
'fetches associated objects for 1:N associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
User
.
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 N:M associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
hasMany
(
this
.
User
)
it
(
'fetches associated objects for 1:N associations (2nd direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
belongsTo
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
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
})
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
it
(
'fetches associated objects for N:M associations (1st direction)'
,
function
(
done
)
{
this
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
hasMany
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
User
.
findAll
({
where
:
{
'UserWithNames.id'
:
user1
.
id
},
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
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
User
.
findAll
({
where
:
{
'UserWithNames.id'
:
user1
.
id
},
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
})
}.
bind
(
this
))
//- User.create
}.
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
.
User
.
hasMany
(
this
.
Task
)
this
.
Task
.
hasMany
(
this
.
User
)
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
Task
.
findAll
({
where
:
{
'Tasks.id'
:
task1
.
id
},
include
:
[
'UserWithName'
]
}).
success
(
function
(
tasks
)
{
expect
(
tasks
[
0
].
userWithNames
).
toBeDefined
()
expect
(
tasks
[
0
].
userWithNames
.
map
(
function
(
u
)
{
return
u
.
id
})
).
toEqual
(
[
user1
.
id
]
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
User
.
create
({
name
:
'barfooz'
}).
success
(
function
(
user1
)
{
this
.
Task
.
create
({
title
:
'task1'
}).
success
(
function
(
task1
)
{
this
.
Task
.
create
({
title
:
'task2'
}).
success
(
function
(
task2
)
{
user1
.
setTasks
([
task1
,
task2
]).
success
(
function
()
{
this
.
Task
.
findAll
({
where
:
{
'Tasks.id'
:
task1
.
id
},
include
:
[
'UserWithName'
]
}).
success
(
function
(
tasks
)
{
expect
(
tasks
[
0
].
userWithNames
).
toBeDefined
()
expect
(
tasks
[
0
].
userWithNames
.
map
(
function
(
u
)
{
return
u
.
id
})
).
toEqual
(
[
user1
.
id
]
)
done
()
})
}.
bind
(
this
))
//- setTask
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- Task.create
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
}.
bind
(
this
))
//- User.create
}.
bind
(
this
))
//- sequelize.sync
})
})
//- describe: findAll
describe
(
'min'
,
function
()
{
before
(
function
(
done
)
{
this
.
UserWithAge
=
this
.
sequelize
.
define
(
'UserWithAge'
,
{
age
:
Sequelize
.
INTEGER
})
})
})
//- describe: findAll
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
.
create
({
age
:
2
}).
success
(
function
()
{
this
.
UserWithAge
.
create
({
age
:
3
}).
success
(
function
()
{
this
.
UserWithAge
.
min
(
'age'
).
success
(
function
(
min
)
{
expect
(
min
).
toEqual
(
2
)
done
()
})
}.
bind
(
this
))
this
.
UserWithAge
.
sync
({
force
:
true
}).
success
(
done
)
})
it
(
"should return the min value"
,
function
(
done
)
{
this
.
UserWithAge
.
create
({
age
:
2
}).
success
(
function
()
{
this
.
UserWithAge
.
create
({
age
:
3
}).
success
(
function
()
{
this
.
UserWithAge
.
min
(
'age'
).
success
(
function
(
min
)
{
expect
(
min
).
toEqual
(
2
)
done
()
})
}.
bind
(
this
))
})
}.
bind
(
this
))
})
it
(
'allows sql logging'
,
function
(
done
)
{
this
.
UserWithAge
.
min
(
'age'
).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
done
()
})
it
(
'allows sql logging'
,
function
(
done
)
{
this
.
UserWithAge
.
min
(
'age'
).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
done
()
})
})
//- describe: min
describe
(
'max'
,
function
()
{
before
(
function
(
done
)
{
this
.
UserWithAge
=
this
.
sequelize
.
define
(
'UserWithAge'
,
{
age
:
Sequelize
.
INTEGER
})
})
})
//- describe: min
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
.
create
({
age
:
2
}).
success
(
function
()
{
this
.
UserWithAge
.
create
({
age
:
3
}).
success
(
function
()
{
this
.
UserWithAge
.
max
(
'age'
).
success
(
function
(
max
)
{
expect
(
max
).
toEqual
(
3
)
done
()
})
}.
bind
(
this
))
this
.
UserWithAge
.
sync
({
force
:
true
}).
success
(
done
)
})
it
(
"should return the max value"
,
function
(
done
)
{
this
.
UserWithAge
.
create
({
age
:
2
}).
success
(
function
()
{
this
.
UserWithAge
.
create
({
age
:
3
}).
success
(
function
()
{
this
.
UserWithAge
.
max
(
'age'
).
success
(
function
(
max
)
{
expect
(
max
).
toEqual
(
3
)
done
()
})
}.
bind
(
this
))
})
}.
bind
(
this
))
})
it
(
'allows sql logging'
,
function
(
done
)
{
this
.
UserWithAge
.
max
(
'age'
).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
done
()
})
it
(
'allows sql logging'
,
function
(
done
)
{
this
.
UserWithAge
.
max
(
'age'
).
on
(
'sql'
,
function
(
sql
)
{
expect
(
sql
).
toBeDefined
()
expect
(
sql
.
toUpperCase
().
indexOf
(
"SELECT"
)).
toBeGreaterThan
(
-
1
)
done
()
})
})
//- describe: max
})
})
})
//- describe: max
})
spec/dao.spec.js
View file @
a59c409
if
(
typeof
require
===
'function'
)
{
const
buster
=
require
(
"buster"
)
,
dialects
=
[
'sqlite'
,
'mysql'
,
'postgres'
]
,
Helpers
=
require
(
'./buster-helpers'
)
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'./buster-helpers'
)
,
dialect
=
Helpers
.
getTestDialect
(
)
}
buster
.
spec
.
expose
()
dialects
.
forEach
(
function
(
dialect
)
{
describe
(
'DAO@'
+
dialect
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] DAO"
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
Helpers
.
initTests
({
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
,
DataTypes
)
{
self
.
sequelize
=
sequelize
self
.
User
=
sequelize
.
define
(
'User'
,
{
username
:
{
type
:
DataTypes
.
STRING
},
touchedAt
:
{
type
:
DataTypes
.
DATE
,
defaultValue
:
DataTypes
.
NOW
},
aNumber
:
{
type
:
DataTypes
.
INTEGER
}
})
},
onComplete
:
function
(
sequelize
)
{
self
.
User
.
sync
({
force
:
true
}).
success
(
done
)
}
})
Helpers
.
initTests
({
dialect
:
dialect
,
beforeComplete
:
function
(
sequelize
,
DataTypes
)
{
self
.
sequelize
=
sequelize
self
.
User
=
sequelize
.
define
(
'User'
,
{
username
:
{
type
:
DataTypes
.
STRING
},
touchedAt
:
{
type
:
DataTypes
.
DATE
,
defaultValue
:
DataTypes
.
NOW
},
aNumber
:
{
type
:
DataTypes
.
INTEGER
}
})
},
onComplete
:
function
()
{
self
.
User
.
sync
({
force
:
true
}).
success
(
done
)
}
})
})
describe
(
'default values'
,
function
()
{
describe
(
'current date'
,
function
()
{
it
(
'should store a date in touchedAt'
,
function
()
{
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
expect
(
user
.
touchedAt
instanceof
Date
).
toBeTrue
()
})
describe
(
'default values'
,
function
()
{
describe
(
'current date'
,
function
()
{
it
(
'should store a date in touchedAt'
,
function
()
{
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
expect
(
user
.
touchedAt
instanceof
Date
).
toBeTrue
()
})
it
(
"should store the current date in touchedAt"
,
function
()
{
this
.
useFakeTimers
().
tick
(
5000
)
it
(
"should store the current date in touchedAt"
,
function
()
{
this
.
useFakeTimers
().
tick
(
5000
)
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
expect
(
+
user
.
touchedAt
).
toBe
(
5000
)
})
var
user
=
this
.
User
.
build
({
username
:
'a user'
})
expect
(
+
user
.
touchedAt
).
toBe
(
5000
)
})
})
})
describe
(
'complete'
,
function
()
{
it
(
"gets triggered if an error occurs"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
"asdasdasd"
}).
complete
(
function
(
err
,
result
)
{
expect
(
err
).
toBeDefined
()
expect
(
err
.
message
).
toBeDefined
()
done
()
})
describe
(
'complete'
,
function
()
{
it
(
"gets triggered if an error occurs"
,
function
(
done
)
{
this
.
User
.
find
({
where
:
"asdasdasd"
}).
complete
(
function
(
err
,
result
)
{
expect
(
err
).
toBeDefined
()
expect
(
err
.
message
).
toBeDefined
()
done
()
})
})
it
(
"gets triggered if everything was ok"
,
function
(
done
)
{
this
.
User
.
count
().
complete
(
function
(
err
,
result
)
{
expect
(
err
).
toBeNull
()
expect
(
result
).
toBeDefined
()
done
()
})
it
(
"gets triggered if everything was ok"
,
function
(
done
)
{
this
.
User
.
count
().
complete
(
function
(
err
,
result
)
{
expect
(
err
).
toBeNull
()
expect
(
result
).
toBeDefined
()
done
()
})
})
})
describe
(
'save'
,
function
()
{
it
(
'takes zero into account'
,
function
(
done
)
{
this
.
User
.
build
({
aNumber
:
0
}).
save
([
'aNumber'
]).
success
(
function
(
user
)
{
expect
(
user
.
aNumber
).
toEqual
(
0
)
done
()
})
describe
(
'save'
,
function
()
{
it
(
'takes zero into account'
,
function
(
done
)
{
this
.
User
.
build
({
aNumber
:
0
}).
save
([
'aNumber'
]).
success
(
function
(
user
)
{
expect
(
user
.
aNumber
).
toEqual
(
0
)
done
()
})
})
})
describe
(
'toJSON'
,
function
toJSON
()
{
before
(
function
(
done
)
{
this
.
User
=
this
.
sequelize
.
define
(
'UserWithUsernameAndAgeAndIsAdmin'
,
{
username
:
Helpers
.
Sequelize
.
STRING
,
age
:
Helpers
.
Sequelize
.
INTEGER
,
isAdmin
:
Helpers
.
Sequelize
.
BOOLEAN
},
{
timestamps
:
false
,
logging
:
true
})
this
.
User
.
sync
({
force
:
true
}).
success
(
done
)
describe
(
'toJSON'
,
function
toJSON
()
{
before
(
function
(
done
)
{
this
.
User
=
this
.
sequelize
.
define
(
'UserWithUsernameAndAgeAndIsAdmin'
,
{
username
:
Helpers
.
Sequelize
.
STRING
,
age
:
Helpers
.
Sequelize
.
INTEGER
,
isAdmin
:
Helpers
.
Sequelize
.
BOOLEAN
},
{
timestamps
:
false
,
logging
:
true
})
it
(
'returns an object containing all values'
,
function
()
{
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
})
})
this
.
User
.
sync
({
force
:
true
}).
success
(
done
)
})
it
(
'returns a response that can be stringified
'
,
function
()
{
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}'
)
})
it
(
'returns an object containing all values
'
,
function
()
{
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 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
})
})
it
(
'returns a response that can be stringified'
,
function
()
{
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}'
)
})
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') {
buster
.
spec
.
expose
()
describe
(
dialect
,
function
()
{
describe
(
'=>DAO'
,
function
()
{
describe
(
'validations'
,
function
()
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
dialect
:
dialect
,
onComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
done
()
}.
bind
(
this
)
})
})
//- before
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] DAO"
,
function
()
{
describe
(
'validations'
,
function
()
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
dialect
:
dialect
,
onComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
done
()
}.
bind
(
this
)
})
})
//- before
var
checks
=
{
is
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"0"
,
pass
:
"a"
},
not
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"a"
,
pass
:
"0"
},
isEmail
:
{
fail
:
"a"
,
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"
}
var
checks
=
{
is
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"0"
,
pass
:
"a"
},
not
:
{
spec
:
{
args
:
[
"[a-z]"
,
'i'
]
},
fail
:
"a"
,
pass
:
"0"
},
isEmail
:
{
fail
:
"a"
,
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"
}
}
for
(
var
validator
in
checks
)
{
if
(
checks
.
hasOwnProperty
(
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
]
for
(
var
validator
in
checks
)
{
if
(
checks
.
hasOwnProperty
(
validator
))
{
var
validatorDetails
=
checks
[
validator
]
it
(
'correctly specifies an instance as invalid using a value of "'
+
failingValue
+
'" for the validation "'
+
validator
+
'"'
,
function
()
{
var
validations
=
{}
,
message
=
validator
+
"("
+
failingValue
+
")"
if
(
!
validatorDetails
.
hasOwnProperty
(
"raw"
))
{
validatorDetails
.
fail
=
[
validatorDetails
.
fail
]
validatorDetails
.
pass
=
[
validatorDetails
.
pass
]
}
if
(
validatorDetails
.
hasOwnProperty
(
'spec'
))
{
validations
[
validator
]
=
validatorDetails
.
spec
}
else
{
validations
[
validator
]
=
{}
}
//////////////////////////
// test the error cases //
//////////////////////////
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
(),
{
name
:
{
type
:
Sequelize
.
STRING
,
validate
:
validations
}
})
if
(
validatorDetails
.
hasOwnProperty
(
'spec'
))
{
validations
[
validator
]
=
validatorDetails
.
spec
}
else
{
validations
[
validator
]
=
{}
}
var
failingUser
=
UserFail
.
build
({
name
:
failingValue
})
,
errors
=
failingUser
.
validate
()
validations
[
validator
].
msg
=
message
expect
(
errors
).
not
.
toBeNull
()
expect
(
errors
).
toEqual
({
name
:
[
message
]
})
var
UserFail
=
this
.
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
name
:
{
type
:
Sequelize
.
STRING
,
validate
:
validations
}
})
}
////////////////////////////
// test the success cases //
////////////////////////////
for
(
var
j
=
0
;
j
<
validatorDetails
.
pass
.
length
;
j
++
)
{
var
succeedingValue
=
validatorDetails
.
pass
[
j
]
var
failingUser
=
UserFail
.
build
({
name
:
failingValue
})
,
errors
=
failingUser
.
validate
()
it
(
'correctly specifies an instance as valid using a value of "'
+
succeedingValue
+
'" for the validation "'
+
validator
+
'"'
,
function
()
{
var
validations
=
{}
expect
(
errors
).
not
.
toBeNull
()
expect
(
errors
).
toEqual
({
name
:
[
message
]
})
})
}
if
(
validatorDetails
.
hasOwnProperty
(
'spec'
))
{
validations
[
validator
]
=
validatorDetails
.
spec
}
else
{
validations
[
validator
]
=
{}
}
////////////////////////////
// test the success cases //
////////////////////////////
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
(),
{
name
:
{
type
:
Sequelize
.
STRING
,
validate
:
validations
}
})
validations
[
validator
].
msg
=
validator
+
"("
+
succeedingValue
+
")"
var
successfulUser
=
UserSuccess
.
build
({
name
:
succeedingValue
})
expect
(
successfulUser
.
validate
()).
toBeNull
()
var
UserSuccess
=
this
.
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
name
:
{
type
:
Sequelize
.
STRING
,
validate
:
validations
}
})
}
var
successfulUser
=
UserSuccess
.
build
({
name
:
succeedingValue
})
expect
(
successfulUser
.
validate
()).
toBeNull
()
})
}
}
}
it
(
'correctly validates using custom validation methods'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
name
:
{
type
:
Sequelize
.
STRING
,
validate
:
{
customFn
:
function
(
val
)
{
if
(
val
!==
"2"
)
{
throw
new
Error
(
"name should equal '2'"
)
}
it
(
'correctly validates using custom validation methods'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
name
:
{
type
:
Sequelize
.
STRING
,
validate
:
{
customFn
:
function
(
val
)
{
if
(
val
!==
"2"
)
{
throw
new
Error
(
"name should equal '2'"
)
}
}
}
})
}
})
var
failingUser
=
User
.
build
({
name
:
"3"
})
,
errors
=
failingUser
.
validate
()
var
failingUser
=
User
.
build
({
name
:
"3"
})
,
errors
=
failingUser
.
validate
()
expect
(
errors
).
not
.
toBeNull
(
null
)
expect
(
errors
).
toEqual
({
name
:
[
"name should equal '2'"
]
})
expect
(
errors
).
not
.
toBeNull
(
null
)
expect
(
errors
).
toEqual
({
name
:
[
"name should equal '2'"
]
})
var
successfulUser
=
User
.
build
({
name
:
"2"
})
expect
(
successfulUser
.
validate
()).
toBeNull
()
})
var
successfulUser
=
User
.
build
({
name
:
"2"
})
expect
(
successfulUser
.
validate
()).
toBeNull
()
})
})
})
spec/query-chainer.spec.js
View file @
a59c409
...
...
@@ -2,13 +2,14 @@ if(typeof require === 'function') {
const
buster
=
require
(
"buster"
)
,
QueryChainer
=
require
(
"../lib/query-chainer"
)
,
CustomEventEmitter
=
require
(
"../lib/emitters/custom-event-emitter"
)
,
Helpers
=
require
(
'./buster-helpers'
)
,
dialect
=
Helpers
.
getTestDialect
()
}
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
1000
describe
(
'QueryChainer'
,
function
()
{
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] QueryChainer"
,
function
()
{
before
(
function
()
{
this
.
queryChainer
=
new
QueryChainer
()
})
...
...
spec/sequelize.spec.js
View file @
a59c409
if
(
typeof
require
===
'function'
)
{
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'./buster-helpers'
)
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'./buster-helpers'
)
,
dialect
=
Helpers
.
getTestDialect
()
}
buster
.
spec
.
expose
()
describe
(
'Sequelize'
,
function
()
{
describe
(
"["
+
dialect
.
toUpperCase
()
+
"] Sequelize"
,
function
()
{
before
(
function
(
done
)
{
Helpers
.
initTests
({
beforeComplete
:
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
}.
bind
(
this
),
...
...
@@ -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
)
{
expect
(
result
).
toBeNull
()
done
()
...
...
spec/sqlite/dao.spec.js
View file @
a59c409
if
(
typeof
require
===
'function'
)
{
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'../buster-helpers'
)
,
dialect
=
Helpers
.
getTestDialect
()
}
buster
.
spec
.
expose
()
describe
(
'DAO@sqlite'
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
if
(
dialect
===
'sqlite'
)
{
describe
(
'[SQLITE] DAO'
,
function
()
{
before
(
function
(
done
)
{
var
self
=
this
Helpers
.
initTests
({
dialect
:
'sqlite'
,
beforeComplete
:
function
(
sequelize
,
DataTypes
)
{
self
.
sequelize
=
sequelize
Helpers
.
initTests
({
dialect
:
'sqlite'
,
beforeComplete
:
function
(
sequelize
,
DataTypes
)
{
self
.
sequelize
=
sequelize
self
.
User
=
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
})
},
onComplete
:
function
(
sequelize
)
{
self
.
User
.
sync
({
force
:
true
}).
success
(
done
)
}
self
.
User
=
sequelize
.
define
(
'User'
,
{
username
:
DataTypes
.
STRING
})
},
onComplete
:
function
()
{
self
.
User
.
sync
({
force
:
true
}).
success
(
done
)
}
})
})
})
describe
(
'findAll'
,
function
()
{
it
(
"handles dates correctly"
,
function
(
done
)
{
var
self
=
this
describe
(
'findAll'
,
function
()
{
it
(
"handles dates correctly"
,
function
(
done
)
{
var
self
=
this
this
.
User
.
create
({
username
:
'user'
,
createdAt
:
new
Date
(
2011
,
04
,
04
)
})
.
success
(
function
(
oldUser
)
{
self
.
User
.
create
({
username
:
'new user'
})
.
success
(
function
(
newUser
)
{
self
.
User
.
findAll
({
where
:
[
'createdAt > ?'
,
new
Date
(
2012
,
01
,
01
)]
}).
success
(
function
(
users
)
{
expect
(
users
.
length
).
toEqual
(
1
)
done
()
this
.
User
.
create
({
username
:
'user'
,
createdAt
:
new
Date
(
2011
,
04
,
04
)
})
.
success
(
function
(
oldUser
)
{
self
.
User
.
create
({
username
:
'new user'
})
.
success
(
function
(
newUser
)
{
self
.
User
.
findAll
({
where
:
[
'createdAt > ?'
,
new
Date
(
2012
,
01
,
01
)]
}).
success
(
function
(
users
)
{
expect
(
users
.
length
).
toEqual
(
1
)
done
()
})
})
})
})
.
error
(
function
(
err
)
{
console
.
log
(
err
)
})
})
.
error
(
function
(
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