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
不要怂,就是干,撸起袖子干!
You need to sign in or sign up before continuing.
Commit 65c0a284
authored
Nov 01, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added charset definition + set to latin1 in tests
1 parent
485cf460
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
122 additions
and
130 deletions
changelog.md
lib/sequelize/model-definition.js
lib/sequelize/sequelize.js
test/ConnectorManager/idle.js
test/Model/add-remove-association.js
test/Model/belongs-to.js
test/Model/build.js
test/Model/count.js
test/Model/create.js
test/Model/destroy.js
test/Model/equals.js
test/Model/find-findAll-all.js
test/Model/has-many.js
test/Model/has-one.js
test/Model/is-new-record.js
test/Model/save.js
test/Model/sync-drop.js
test/Model/update-attributes.js
test/Model/values.js
test/Sequelize/import.js
test/Sequelize/sync.js
changelog.md
View file @
65c0a28
...
...
@@ -113,3 +113,7 @@
-
[
FEATURE
]
getModel for modelManager for getting a model without storing it in a variable; use it via sequelize.modelManager.getModel('User')
-
[
TEST
]
test suite refactoring for jasmine
# v1.2.1 #
-
[
REFACTORING
]
renamed the global options for sync, query and define on sequelize; before: options.queryOptions; now: options.query
-
[
FEATURE
]
allow definition of charset via global define option in sequelize or via an option in sequelize.define
-
[
TEST
]
force latin1 charset for travis
lib/sequelize/model-definition.js
View file @
65c0a28
...
...
@@ -68,7 +68,7 @@ ModelDefinition.prototype.query = function() {
}
ModelDefinition
.
prototype
.
sync
=
function
(
options
)
{
options
=
options
||
{}
options
=
Utils
.
merge
(
options
||
{},
this
.
options
)
var
self
=
this
var
doQuery
=
function
()
{
...
...
lib/sequelize/sequelize.js
View file @
65c0a28
...
...
@@ -7,7 +7,9 @@ var Utils = require("./utils")
var
Sequelize
=
module
.
exports
=
function
(
database
,
username
,
password
,
options
)
{
options
=
options
||
{}
Utils
.
_
.
reject
(
options
,
function
(
_
,
key
)
{
return
[
"host"
,
"port"
,
"disableTableNameModification"
].
indexOf
(
key
)
>
-
1
})
Utils
.
_
.
reject
(
options
,
function
(
_
,
key
)
{
return
[
"host"
,
"port"
,
"disableTableNameModification"
].
indexOf
(
key
)
>
-
1
})
this
.
options
=
options
this
.
config
=
{
...
...
@@ -27,7 +29,8 @@ var instanceMethods = {
define
:
function
(
modelName
,
attributes
,
options
)
{
options
=
options
||
{}
if
(
this
.
options
.
defineOptions
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
defineOptions
)
if
(
this
.
options
.
define
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
define
)
var
model
=
this
.
modelManager
.
addModel
(
new
ModelDefinition
(
modelName
,
attributes
,
options
))
...
...
@@ -42,7 +45,8 @@ var instanceMethods = {
query
:
function
(
sql
,
callee
,
options
)
{
options
=
options
||
{}
if
(
this
.
options
.
queryOptions
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
queryOptions
)
if
(
this
.
options
.
query
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
query
)
options
.
logging
=
this
.
options
.
hasOwnProperty
(
'logging'
)
?
this
.
options
.
logging
:
true
...
...
@@ -52,7 +56,8 @@ var instanceMethods = {
sync
:
function
(
options
)
{
options
=
options
||
{}
if
(
this
.
options
.
syncOptions
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
syncOptions
)
if
(
this
.
options
.
sync
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
sync
)
var
self
=
this
var
eventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
...
...
test/ConnectorManager/idle.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
module
.
exports
=
{
'it should work correctly after being idle'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
username
:
'user1'
}).
on
(
'success'
,
function
()
{
User
.
count
().
on
(
'success'
,
function
(
count
)
{
...
...
@@ -19,4 +19,4 @@ module.exports = {
})
})
}
}
\ No newline at end of file
}
test/Model/add-remove-association.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
var
initialize
=
function
(
options
,
callback
)
{
options
=
options
||
{}
options
.
taskCount
=
options
.
taskCount
||
1
options
.
userCount
=
options
.
userCount
||
1
var
num
=
config
.
rand
()
,
User
=
sequelize
.
define
(
'User'
+
num
,
{
name
:
Sequelize
.
STRING
})
,
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
name
:
Sequelize
.
STRING
})
...
...
@@ -16,13 +16,13 @@ var initialize = function(options, callback) {
User
.
hasMany
(
Task
,
{
as
:
'Tasks'
})
Task
.
hasMany
(
User
,
{
as
:
'Users'
})
sequelize
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
for
(
var
i
=
0
;
i
<
options
.
taskCount
;
i
++
)
chainer
.
add
(
Task
.
create
({
name
:
'task'
+
i
}))
for
(
var
i
=
0
;
i
<
options
.
userCount
;
i
++
)
chainer
.
add
(
User
.
create
({
name
:
'user'
+
i
}))
chainer
.
run
().
on
(
'success'
,
function
()
{
callback
(
Task
,
User
)
})
...
...
@@ -46,7 +46,7 @@ module.exports = {
})
})
})
})
})
})
...
...
@@ -62,7 +62,7 @@ module.exports = {
user
.
setTasks
(
tasks
).
on
(
'success'
,
function
()
{
user
.
getTasks
().
on
(
'success'
,
function
(
_tasks
)
{
assert
.
eql
(
_tasks
.
length
,
tasks
.
length
)
user
.
removeTask
(
tasks
[
0
]).
on
(
'success'
,
function
()
{
user
.
getTasks
().
on
(
'success'
,
function
(
_tasks
)
{
assert
.
eql
(
_tasks
.
length
,
tasks
.
length
-
1
)
...
...
@@ -78,4 +78,4 @@ module.exports = {
})
})
}
}
\ No newline at end of file
}
test/Model/belongs-to.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
module
.
exports
=
{
'it should correctly add the foreign id'
:
function
()
{
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
Task
.
belongsTo
(
User
)
assert
.
eql
(
Task
.
attributes
[
'User'
+
num
+
'Id'
],
"INT"
)
},
...
...
@@ -16,14 +16,14 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
},
{
underscored
:
true
})
Task
.
belongsTo
(
User
)
assert
.
eql
(
Task
.
attributes
[
'user'
+
num
+
'_id'
],
"INT"
)
},
'it should correctly add the foreign id if foreignKey is passed'
:
function
()
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
config
.
rand
(),
{
title
:
Sequelize
.
STRING
})
Task
.
belongsTo
(
User
,
{
foreignKey
:
'person_id'
})
assert
.
eql
(
Task
.
attributes
[
'person_id'
],
"INT"
)
},
...
...
@@ -31,9 +31,9 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
Task
.
belongsTo
(
User
)
var
t
=
Task
.
build
({
title
:
'asd'
})
assert
.
isDefined
(
t
[
'setUser'
+
num
])
assert
.
isDefined
(
t
[
'getUser'
+
num
])
...
...
@@ -41,9 +41,9 @@ module.exports = {
'it should define getter and setter according to passed as option'
:
function
()
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
config
.
rand
(),
{
title
:
Sequelize
.
STRING
})
Task
.
belongsTo
(
User
,
{
as
:
'Person'
})
var
t
=
Task
.
build
({
title
:
'asd'
})
assert
.
isDefined
(
t
.
setPerson
)
assert
.
isDefined
(
t
.
getPerson
)
...
...
@@ -52,16 +52,16 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
Task
.
belongsTo
(
User
)
var
t
=
Task
.
build
({
title
:
'asd'
})
assert
.
isNull
(
t
[
'User'
+
num
+
'Id'
])
},
'it should set and get the correct object'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
config
.
rand
(),
{
title
:
Sequelize
.
STRING
})
Task
.
belongsTo
(
User
,
{
as
:
'User'
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
...
...
@@ -82,9 +82,9 @@ module.exports = {
'it should correctly delete associations'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
config
.
rand
(),
{
title
:
Sequelize
.
STRING
})
Task
.
belongsTo
(
User
,
{
as
:
'User'
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
Task
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
username
:
'asd'
}).
on
(
'success'
,
function
(
u
)
{
...
...
@@ -110,7 +110,7 @@ module.exports = {
Person
.
belongsTo
(
Person
,
{
as
:
'Mother'
,
foreignKey
:
'MotherId'
})
Person
.
belongsTo
(
Person
,
{
as
:
'Father'
,
foreignKey
:
'FatherId'
})
Person
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
var
p
=
Person
.
build
()
assert
.
isDefined
(
p
.
setFather
)
...
...
@@ -125,4 +125,4 @@ module.exports = {
Person
.
belongsTo
(
Person
,
{
as
:
'Mother'
})
assert
.
eql
(
Person
.
associations
[
"MotherPerson"
+
num
+
"s"
].
options
.
foreignKey
,
'MotherId'
)
}
}
\ No newline at end of file
}
test/Model/build.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
var
initUsers
=
function
(
num
,
callback
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
,
users
=
[]
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
while
(
num
--
)
users
.
push
(
User
.
build
({
name
:
'user'
+
num
,
bio
:
'foobar'
}))
callback
(
users
,
User
)
...
...
@@ -37,4 +37,4 @@ module.exports = {
assert
.
eql
(
Task
.
build
().
foobar
,
'asd'
)
assert
.
eql
(
Task
.
build
().
flag
,
false
)
}
}
\ No newline at end of file
}
test/Model/count.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
module
.
exports
=
{
'it should correctly count all objects'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
})
...
...
@@ -30,4 +30,4 @@ module.exports = {
})
})
}
}
\ No newline at end of file
}
test/Model/create.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
var
initUsers
=
function
(
num
,
callback
)
{
return
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
...
...
@@ -49,4 +49,4 @@ module.exports = {
})
})
}
}
\ No newline at end of file
}
test/Model/destroy.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
module
.
exports
=
{
'destroy should delete a saved record from the database'
:
function
(
exit
)
{
...
...
@@ -32,4 +32,4 @@ module.exports = {
})
})
}
}
\ No newline at end of file
}
test/Model/equals.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
module
.
exports
=
{
'it should correctly determine equal objects'
:
function
(
exit
)
{
...
...
test/Model/find-findAll-all.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
var
initUsers
=
function
(
num
,
callback
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
...
...
@@ -11,7 +11,7 @@ var initUsers = function(num, callback) {
else
callback
(
user
,
User
)
})
}
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
createUser
()
})
...
...
@@ -118,4 +118,4 @@ module.exports = {
})
})
}
}
\ No newline at end of file
}
test/Model/has-many.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
module
.
exports
=
{
'it should correctly add the foreign id - monodirectional'
:
function
()
{
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
)
assert
.
eql
(
Task
.
attributes
[
'User'
+
num
+
'Id'
],
"INT"
)
},
...
...
@@ -29,13 +29,13 @@ module.exports = {
assert
.
isDefined
(
model
.
attributes
[
'Task'
+
num
+
'Id'
])
exit
(
function
(){})
}
})
})
},
'it should correctly add the foreign id with underscore - monodirectional'
:
function
()
{
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
},
{
underscored
:
true
})
Task
.
hasMany
(
User
)
assert
.
isDefined
(
User
.
attributes
[
'task'
+
num
+
'_id'
])
},
...
...
@@ -43,10 +43,10 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
},
{
underscored
:
true
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
Task
.
hasMany
(
User
)
User
.
hasMany
(
Task
)
assert
.
isUndefined
(
Task
.
attributes
[
'user'
+
num
+
'_id'
])
assert
.
isUndefined
(
User
.
attributes
[
'user'
+
num
+
'_id'
])
...
...
@@ -61,7 +61,7 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
},
{
underscored
:
true
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
,
{
foreignKey
:
'person_id'
})
assert
.
eql
(
Task
.
attributes
.
person_id
,
"INT"
)
},
...
...
@@ -69,10 +69,10 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
},
{
underscored
:
true
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
,
{
foreignKey
:
'person_id'
})
Task
.
hasMany
(
User
,
{
foreignKey
:
'work_item_id'
})
sequelize
.
modelManager
.
models
.
forEach
(
function
(
model
)
{
if
(
model
.
tableName
==
(
Task
.
tableName
+
User
.
tableName
))
{
assert
.
isDefined
(
model
.
attributes
.
person_id
)
...
...
@@ -84,9 +84,9 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
)
var
u
=
User
.
build
({
username
:
'asd'
})
assert
.
isDefined
(
u
[
'setTask'
+
num
+
"s"
])
assert
.
isDefined
(
u
[
'getTask'
+
num
+
"s"
])
...
...
@@ -95,14 +95,14 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
)
Task
.
hasMany
(
User
)
var
u
=
User
.
build
({
username
:
'asd'
})
assert
.
isDefined
(
u
[
'setTask'
+
num
+
"s"
])
assert
.
isDefined
(
u
[
'getTask'
+
num
+
"s"
])
var
t
=
Task
.
build
({
title
:
'foobar'
})
assert
.
isDefined
(
t
[
'setUser'
+
num
+
's'
])
assert
.
isDefined
(
t
[
'getUser'
+
num
+
's'
])
...
...
@@ -111,9 +111,9 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
,
{
as
:
'Tasks'
})
var
u
=
User
.
build
({
username
:
'asd'
})
assert
.
isDefined
(
u
.
setTasks
)
assert
.
isDefined
(
u
.
getTasks
)
...
...
@@ -122,14 +122,14 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
,
{
as
:
'Tasks'
})
Task
.
hasMany
(
User
,
{
as
:
'Users'
})
var
u
=
User
.
build
({
username
:
'asd'
})
assert
.
isDefined
(
u
.
setTasks
)
assert
.
isDefined
(
u
.
getTasks
)
var
t
=
Task
.
build
({
title
:
'asd'
})
assert
.
isDefined
(
t
.
setUsers
)
assert
.
isDefined
(
t
.
getUsers
)
...
...
@@ -137,26 +137,26 @@ module.exports = {
'it should set and get the correct objects - monodirectional'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
config
.
rand
(),
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
,
{
as
:
'Tasks'
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
Task
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
username
:
'name'
}).
on
(
'success'
,
function
(
user
)
{
Task
.
create
({
title
:
'task1'
}).
on
(
'success'
,
function
(
task1
)
{
Task
.
create
({
title
:
'task2'
}).
on
(
'success'
,
function
(
task2
)
{
user
.
setTasks
([
task1
,
task2
]).
on
(
'success'
,
function
()
{
user
.
getTasks
().
on
(
'success'
,
function
(
tasks
)
{
assert
.
eql
(
tasks
.
length
,
2
)
exit
(
function
(){})
})
})
})
})
})
})
})
...
...
@@ -164,22 +164,22 @@ module.exports = {
'it should set and get the correct objects - bidirectional'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
config
.
rand
(),
{
title
:
Sequelize
.
STRING
})
User
.
hasMany
(
Task
,
{
as
:
'Tasks'
})
Task
.
hasMany
(
User
,
{
as
:
'Users'
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
Task
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
username
:
'name'
}).
on
(
'success'
,
function
(
user1
)
{
User
.
create
({
username
:
'name2'
}).
on
(
'success'
,
function
(
user2
)
{
Task
.
create
({
title
:
'task1'
}).
on
(
'success'
,
function
(
task1
)
{
Task
.
create
({
title
:
'task2'
}).
on
(
'success'
,
function
(
task2
)
{
user1
.
setTasks
([
task1
,
task2
]).
on
(
'success'
,
function
()
{
user1
.
getTasks
().
on
(
'success'
,
function
(
tasks
)
{
assert
.
eql
(
tasks
.
length
,
2
)
task2
.
setUsers
([
user1
,
user2
]).
on
(
'success'
,
function
()
{
task2
.
getUsers
().
on
(
'success'
,
function
(
users
)
{
assert
.
eql
(
users
.
length
,
2
)
...
...
@@ -188,10 +188,10 @@ module.exports = {
})
})
})
})
})
})
})
})
})
...
...
@@ -204,7 +204,7 @@ module.exports = {
Person
.
hasMany
(
Person
,
{
as
:
'Children'
})
Person
.
hasMany
(
Person
,
{
as
:
'Friends'
})
Person
.
hasMany
(
Person
,
{
as
:
'CoWorkers'
})
Person
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
var
modelNames
=
sequelize
.
modelManager
.
models
.
map
(
function
(
model
)
{
return
model
.
tableName
})
,
expectation
=
[
"Person"
+
num
+
"s"
,
"ChildrenPerson"
+
num
+
"s"
,
"CoWorkersPerson"
+
num
+
"s"
,
"FriendsPerson"
+
num
+
"s"
]
...
...
@@ -212,7 +212,7 @@ module.exports = {
expectation
.
forEach
(
function
(
ex
)
{
assert
.
eql
(
modelNames
.
indexOf
(
ex
)
>
-
1
,
true
)
})
exit
(
function
(){})
})
},
...
...
@@ -223,7 +223,7 @@ module.exports = {
Person
.
hasMany
(
Person
,
{
as
:
'Children'
})
Person
.
hasMany
(
Person
,
{
as
:
'Friends'
})
Person
.
hasMany
(
Person
,
{
as
:
'CoWorkers'
})
Person
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
Person
.
create
({
name
:
'foobar'
}).
on
(
'success'
,
function
(
person
)
{
Person
.
create
({
name
:
'friend'
}).
on
(
'success'
,
function
(
friend
)
{
...
...
@@ -238,4 +238,4 @@ module.exports = {
})
})
}
}
\ No newline at end of file
}
test/Model/has-one.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
module
.
exports
=
{
'it should correctly add the foreign id'
:
function
()
{
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
User
.
hasOne
(
Task
)
assert
.
eql
(
Task
.
attributes
[
'User'
+
num
+
'Id'
],
"INT"
)
},
...
...
@@ -16,7 +16,7 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
},
{
underscored
:
true
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
User
.
hasOne
(
Task
)
assert
.
eql
(
Task
.
attributes
[
'user'
+
num
+
'_id'
],
"INT"
)
},
...
...
@@ -24,7 +24,7 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
},
{
underscored
:
true
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
User
.
hasOne
(
Task
,
{
foreignKey
:
'person_id'
})
assert
.
eql
(
Task
.
attributes
.
person_id
,
"INT"
)
},
...
...
@@ -32,9 +32,9 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
User
.
hasOne
(
Task
)
var
u
=
User
.
build
({
username
:
'asd'
})
assert
.
isDefined
(
u
[
'setTask'
+
num
])
assert
.
isDefined
(
u
[
'getTask'
+
num
])
...
...
@@ -43,9 +43,9 @@ module.exports = {
var
num
=
config
.
rand
()
var
User
=
sequelize
.
define
(
'User'
+
num
,
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
num
,
{
title
:
Sequelize
.
STRING
})
User
.
hasOne
(
Task
,
{
as
:
'Task'
})
var
u
=
User
.
build
({
username
:
'asd'
})
assert
.
isDefined
(
u
.
setTask
)
assert
.
isDefined
(
u
.
getTask
)
...
...
@@ -53,9 +53,9 @@ module.exports = {
'it should set and get the correct objects'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
config
.
rand
(),
{
title
:
Sequelize
.
STRING
})
User
.
hasOne
(
Task
,
{
as
:
'Task'
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
Task
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
username
:
'name'
}).
on
(
'success'
,
function
(
user
)
{
...
...
@@ -74,9 +74,9 @@ module.exports = {
'it should correctly unset the obsolete objects'
:
function
(
exit
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
username
:
Sequelize
.
STRING
})
var
Task
=
sequelize
.
define
(
'Task'
+
config
.
rand
(),
{
title
:
Sequelize
.
STRING
})
User
.
hasOne
(
Task
,
{
as
:
'Task'
})
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
Task
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
User
.
create
({
username
:
'name'
}).
on
(
'success'
,
function
(
user
)
{
...
...
@@ -104,7 +104,7 @@ module.exports = {
Person
.
hasOne
(
Person
,
{
as
:
'Mother'
,
foreignKey
:
'MotherId'
})
Person
.
hasOne
(
Person
,
{
as
:
'Father'
,
foreignKey
:
'FatherId'
})
Person
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
var
p
=
Person
.
build
()
assert
.
isDefined
(
p
.
setFather
)
...
...
@@ -119,4 +119,4 @@ module.exports = {
Person
.
hasOne
(
Person
,
{
as
:
'Mother'
})
assert
.
eql
(
Person
.
associations
[
"MotherPerson"
+
num
+
"s"
].
options
.
foreignKey
,
'MotherId'
)
}
}
\ No newline at end of file
}
test/Model/is-new-record.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
var
initUsers
=
function
(
num
,
callback
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
,
users
=
[]
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
while
(
num
--
)
users
.
push
(
User
.
build
({
name
:
'user'
+
num
,
bio
:
'foobar'
}))
callback
(
users
,
User
)
...
...
@@ -64,4 +64,4 @@ module.exports = {
})
})
}
}
\ No newline at end of file
}
test/Model/save.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
module
.
exports
=
{
'save should add a record to the database'
:
function
(
exit
)
{
...
...
@@ -41,4 +41,4 @@ module.exports = {
},
10
)
})
}
}
\ No newline at end of file
}
test/Model/sync-drop.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
,
User
=
sequelize
.
define
(
'User'
,
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
module
.
exports
=
{
...
...
@@ -18,4 +18,4 @@ module.exports = {
'drop should work'
:
function
(
exit
)
{
User
.
drop
().
on
(
'success'
,
function
(){
exit
(
function
(){})})
}
}
\ No newline at end of file
}
test/Model/update-attributes.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
,
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
module
.
exports
=
{
...
...
@@ -58,4 +58,4 @@ module.exports = {
})
})
}
}
\ No newline at end of file
}
test/Model/values.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
var
initUsers
=
function
(
num
,
callback
)
{
var
User
=
sequelize
.
define
(
'User'
+
config
.
rand
(),
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
},
{
timestamps
:
false
})
,
users
=
[]
User
.
sync
({
force
:
true
}).
on
(
'success'
,
function
()
{
while
(
num
--
)
users
.
push
(
User
.
build
({
name
:
'user'
+
num
,
bio
:
'foobar'
}))
callback
(
users
,
User
)
...
...
@@ -20,4 +20,4 @@ module.exports = {
exit
(
function
(){})
})
}
}
\ No newline at end of file
}
test/Sequelize/import.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
module
.
exports
=
{
'the import should work correctly'
:
function
()
{
var
Project
=
sequelize
.
import
(
__dirname
+
"/../project"
)
assert
.
isDefined
(
Project
)
}
}
\ No newline at end of file
}
test/Sequelize/sync.js
View file @
65c0a28
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
,
define
:
{
charset
:
'latin1'
}
})
module
.
exports
=
{
'it should sync all models - so instances can be created and saved to the database without failures'
:
function
(
exit
)
{
...
...
@@ -11,7 +11,7 @@ module.exports = {
var
Task
=
sequelize
.
define
(
'task'
+
config
.
rand
(),
{
title
:
Sequelize
.
STRING
})
sequelize
.
sync
().
on
(
'success'
,
function
()
{
Project
.
create
({
title
:
'bla'
}).
on
(
'success'
,
function
()
{
Task
.
create
({
title
:
'bla'
}).
on
(
'success'
,
function
()
{
...
...
@@ -20,4 +20,4 @@ module.exports = {
})
})
}
}
\ No newline at end of file
}
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