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 30eb3bf4
authored
Feb 27, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests are now using expresso 0.7.2
1 parent
a4c973f4
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
89 additions
and
73 deletions
lib/sequelize/SequelizeTable.js
test/Helper/etc.js
test/Helper/hash.js
test/Helper/sql.js
test/Sequelize/basics.js
test/Sequelize/sqlQueryFor.js
test/Table/associations.js
test/Table/basics.js
test/Table/databaseAccess.js
test/Table/fetchAssociations.js
test/Table/finder.js
test/Table/prepareAssociations.js
lib/sequelize/SequelizeTable.js
View file @
30eb3bf
...
...
@@ -370,6 +370,8 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
}
sequelize
.
query
(
query
,
function
(
result
,
stats
)
{
console
.
log
(
self
.
id
)
console
.
log
(
stats
)
self
.
id
=
self
.
id
||
stats
.
insert_id
if
(
callback
)
callback
(
self
)
})
...
...
test/Helper/etc.js
View file @
30eb3bf
var
Sequelize
=
require
(
__dirname
+
"/../../lib/sequelize/Sequelize"
).
Sequelize
var
h
=
Sequelize
.
Helper
var
assert
=
require
(
"assert"
)
module
.
exports
=
{
'log should be defined'
:
function
(
assert
)
{
'log should be defined'
:
function
()
{
assert
.
isNotNull
(
h
.
log
)
assert
.
isDefined
(
h
.
log
)
},
'evaluateTemplate'
:
function
(
assert
)
{
'evaluateTemplate'
:
function
()
{
assert
.
equal
(
h
.
evaluateTemplate
(
"hallo %{foo}!"
,
{
foo
:
'welt'
}),
"hallo welt!"
)
assert
.
equal
(
h
.
evaluateTemplate
(
"hallo %{foo}!"
,
{
foo
:
'welt'
,
bar
:
'asd'
}),
"hallo welt!"
)
},
'Inflection: should be available'
:
function
(
assert
)
{
'Inflection: should be available'
:
function
()
{
assert
.
isDefined
(
h
.
Inflection
)
},
}
\ No newline at end of file
test/Helper/hash.js
View file @
30eb3bf
var
Sequelize
=
require
(
__dirname
+
"/../../lib/sequelize/Sequelize"
).
Sequelize
var
h
=
Sequelize
.
Helper
var
assert
=
require
(
"assert"
)
module
.
exports
=
{
'Hash: forEach'
:
function
(
assert
)
{
'Hash: forEach'
:
function
()
{
var
values
=
[]
var
keys
=
[]
h
.
Hash
.
forEach
({
a
:
1
,
b
:
2
,
c
:
3
},
function
(
value
,
key
)
{
...
...
@@ -12,29 +13,29 @@ module.exports = {
assert
.
eql
(
values
,
[
1
,
2
,
3
])
assert
.
eql
(
keys
,
[
'a'
,
'b'
,
'c'
])
},
'Hash: map'
:
function
(
assert
)
{
'Hash: map'
:
function
()
{
var
hash
=
{
a
:
1
,
b
:
2
,
c
:
3
}
assert
.
eql
(
h
.
Hash
.
map
(
hash
,
function
(
value
,
key
)
{
return
value
}),
[
1
,
2
,
3
])
assert
.
eql
(
h
.
Hash
.
map
(
hash
,
function
(
value
,
key
)
{
return
key
}),
[
'a'
,
'b'
,
'c'
])
},
'Hash: keys'
:
function
(
assert
)
{
'Hash: keys'
:
function
()
{
assert
.
eql
(
h
.
Hash
.
keys
({
a
:
1
,
b
:
2
}),
[
'a'
,
'b'
])
},
'Hash: values'
:
function
(
assert
)
{
'Hash: values'
:
function
()
{
assert
.
eql
(
h
.
Hash
.
values
({
a
:
1
,
b
:
2
}),
[
1
,
2
])
},
'Hash: merge'
:
function
(
assert
)
{
'Hash: merge'
:
function
()
{
var
src
=
{
a
:
1
,
b
:
2
}
var
target
=
{
b
:
3
,
c
:
3
}
assert
.
eql
(
h
.
Hash
.
merge
(
src
,
target
),
{
a
:
1
,
b
:
3
,
c
:
3
})
assert
.
eql
(
h
.
Hash
.
merge
(
src
,
target
,
true
),
{
a
:
1
,
b
:
2
,
c
:
3
})
},
'Hash: without'
:
function
(
assert
)
{
'Hash: without'
:
function
()
{
var
hash
=
{
a
:
1
,
b
:
2
}
assert
.
eql
(
h
.
Hash
.
without
(
hash
,
[
"a"
]),
{
b
:
2
})
},
'Hash: isHash'
:
function
(
assert
)
{
'Hash: isHash'
:
function
()
{
assert
.
eql
(
h
.
Hash
.
isHash
([
1
,
2
]),
false
)
assert
.
eql
(
h
.
Hash
.
isHash
(
1
),
false
)
assert
.
eql
(
h
.
Hash
.
isHash
(
"asd"
),
false
)
...
...
test/Helper/sql.js
View file @
30eb3bf
var
Sequelize
=
require
(
__dirname
+
"/../../lib/sequelize/Sequelize"
).
Sequelize
var
h
=
Sequelize
.
Helper
var
assert
=
require
(
"assert"
)
module
.
exports
=
{
'SQL: manyToManyTableName'
:
function
(
assert
)
{
'SQL: manyToManyTableName'
:
function
()
{
assert
.
equal
(
h
.
SQL
.
manyToManyTableName
(
'foo'
,
'bar'
),
'BarFoo'
)
assert
.
equal
(
h
.
SQL
.
manyToManyTableName
(
'bar'
,
'foo'
),
'BarFoo'
)
},
'SQL: asTableIdentifier'
:
function
(
assert
)
{
'SQL: asTableIdentifier'
:
function
()
{
assert
.
equal
(
h
.
SQL
.
asTableIdentifier
(
'Users'
),
'userId'
)
assert
.
equal
(
h
.
SQL
.
asTableIdentifier
(
'Children'
),
'childId'
)
assert
.
equal
(
h
.
SQL
.
asTableIdentifier
(
'Children'
),
'childId'
)
assert
.
equal
(
h
.
SQL
.
asTableIdentifier
(
'Mice'
),
'mouseId'
)
},
'SQL: asTableName'
:
function
(
assert
)
{
'SQL: asTableName'
:
function
()
{
assert
.
equal
(
h
.
SQL
.
asTableName
(
'User'
),
'Users'
)
assert
.
equal
(
h
.
SQL
.
asTableName
(
'Child'
),
'Children'
)
assert
.
equal
(
h
.
SQL
.
asTableName
(
'Mouse'
),
'Mice'
)
},
'SQL: asTableName with options'
:
function
(
assert
)
{
'SQL: asTableName with options'
:
function
()
{
h
.
configure
({
disableTableNameModification
:
true
})
assert
.
equal
(
h
.
SQL
.
asTableName
(
'User'
),
'User'
)
assert
.
equal
(
h
.
SQL
.
asTableName
(
'Child'
),
'Child'
)
assert
.
equal
(
h
.
SQL
.
asTableName
(
'Mouse'
),
'Mouse'
)
h
.
configure
({
disableTableNameModification
:
false
})
},
'SQL: asSqlDate'
:
function
(
assert
)
{
'SQL: asSqlDate'
:
function
()
{
var
d
=
new
Date
(
Date
.
parse
(
"Tue, 1 Jan 2000 00:00:00 GMT"
))
assert
.
equal
(
h
.
SQL
.
asSqlDate
(
d
),
'2000-01-01 01:00:00'
)
},
'SQL: valuesForInsertQuery'
:
function
(
assert
)
{
'SQL: valuesForInsertQuery'
:
function
()
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
var
result
=
h
.
SQL
.
valuesForInsertQuery
(
new
Day
({
name
:
'asd'
}))
assert
.
eql
(
result
,
[
"'asd'"
,
'NULL'
,
'NULL'
])
},
'SQL: fieldsForInsertQuery'
:
function
(
assert
)
{
'SQL: fieldsForInsertQuery'
:
function
()
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
var
result
=
h
.
SQL
.
fieldsForInsertQuery
(
new
Day
({
name
:
'asd'
}))
assert
.
eql
(
result
,
'`name`, `createdAt`, `updatedAt`'
)
},
'SQL: transformValueByDataType'
:
function
(
assert
)
{
'SQL: transformValueByDataType'
:
function
()
{
assert
.
equal
(
h
.
SQL
.
transformValueByDataType
(
'asd'
,
{
type
:
Sequelize
.
STRING
}),
"'asd'"
)
assert
.
equal
(
h
.
SQL
.
transformValueByDataType
(
'asd'
,
{
type
:
Sequelize
.
TEXT
}),
"'asd'"
)
assert
.
equal
(
h
.
SQL
.
transformValueByDataType
(
6
,
{
type
:
Sequelize
.
INTEGER
}),
"6"
)
...
...
@@ -51,25 +52,25 @@ module.exports = {
var
d
=
new
Date
(
Date
.
parse
(
"Tue, 1 Jan 2000 00:00:00 GMT"
))
assert
.
equal
(
h
.
SQL
.
transformValueByDataType
(
d
,
{
type
:
Sequelize
.
DATE
}),
"'2000-01-01 01:00:00'"
)
},
'SQL: valuesForUpdate'
:
function
(
assert
)
{
'SQL: valuesForUpdate'
:
function
()
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
var
day
=
new
Day
({
name
:
'asd'
})
assert
.
equal
(
h
.
SQL
.
valuesForUpdate
(
day
),
"
name = 'asd', createdAt = NULL, updatedAt
= NULL"
)
assert
.
equal
(
h
.
SQL
.
valuesForUpdate
(
day
,
{
seperator
:
'; '
}),
"
name = 'asd'; createdAt = NULL; updatedAt
= NULL"
)
assert
.
equal
(
h
.
SQL
.
valuesForUpdate
(
day
),
"
`name` = 'asd', `createdAt` = NULL, `updatedAt`
= NULL"
)
assert
.
equal
(
h
.
SQL
.
valuesForUpdate
(
day
,
{
seperator
:
'; '
}),
"
`name` = 'asd'; `createdAt` = NULL; `updatedAt`
= NULL"
)
},
'SQL: hashToWhereConditions'
:
function
(
assert
)
{
'SQL: hashToWhereConditions'
:
function
()
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
var
day
=
new
Day
({
name
:
'asd'
})
assert
.
equal
(
h
.
SQL
.
hashToWhereConditions
(
5
,
Day
.
attributes
),
'`id`=5'
)
assert
.
equal
(
h
.
SQL
.
hashToWhereConditions
({
name
:
'asd'
},
Day
.
attributes
),
"`name`='asd'"
)
},
'SQL: addPrefix'
:
function
(
assert
)
{
'SQL: addPrefix'
:
function
()
{
assert
.
equal
(
h
.
SQL
.
addPrefix
(
'foo'
,
'bar'
,
true
),
'fooBar'
)
assert
.
equal
(
h
.
SQL
.
addPrefix
(
'foo'
,
'bar'
,
false
),
'fooBars'
)
},
'getDataTypeForValue'
:
function
(
assert
)
{
'getDataTypeForValue'
:
function
()
{
var
fct
=
h
.
SQL
.
getDataTypeForValue
assert
.
equal
(
fct
(
1
),
Sequelize
.
INTEGER
)
assert
.
equal
(
fct
(
1.2
),
Sequelize
.
FLOAT
)
...
...
test/Sequelize/basics.js
View file @
30eb3bf
var
Sequelize
=
require
(
__dirname
+
"/../../lib/sequelize/Sequelize"
).
Sequelize
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
var
assert
=
require
(
"assert"
)
module
.
exports
=
{
'test constants'
:
function
(
assert
)
{
'test constants'
:
function
()
{
assert
.
isDefined
(
Sequelize
.
STRING
)
assert
.
isNotNull
(
Sequelize
.
STRING
)
assert
.
isDefined
(
Sequelize
.
TEXT
)
...
...
@@ -10,34 +11,34 @@ module.exports = {
assert
.
isDefined
(
Sequelize
.
INTEGER
)
assert
.
isNotNull
(
Sequelize
.
INTEGER
)
},
'the constructor sets config correctly'
:
function
(
assert
){
'the constructor sets config correctly'
:
function
(){
assert
.
equal
(
s
.
config
.
database
,
'sequelize_test'
)
assert
.
equal
(
s
.
config
.
username
,
'test'
)
assert
.
equal
(
s
.
config
.
password
,
'test'
)
},
'the constructor initializes empty tables hash'
:
function
(
assert
)
{
'the constructor initializes empty tables hash'
:
function
()
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
assert
.
isDefined
(
s
.
tables
)
assert
.
isNotNull
(
s
.
tables
)
assert
.
eql
(
s
.
tables
,
{})
},
'define should return a function'
:
function
(
assert
){
'define should return a function'
:
function
(){
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
assert
.
equal
(
typeof
Day
,
'function'
)
},
'define should add new table to tables'
:
function
(
assert
)
{
'define should add new table to tables'
:
function
()
{
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
assert
.
includes
(
Sequelize
.
Helper
.
Hash
.
keys
(
Day
.
sequelize
.
tables
),
'Day'
)
},
'tableNames should be an empty array if no tables are specified'
:
function
(
assert
){
'tableNames should be an empty array if no tables are specified'
:
function
(){
var
s2
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
assert
.
deepEqual
(
s2
.
tableNames
,
[])
},
'tableNames should be no empty array if tables are specified'
:
function
(
assert
)
{
'tableNames should be no empty array if tables are specified'
:
function
()
{
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
assert
.
deepEqual
(
s
.
tableNames
,
[
'Days'
])
},
'sync: errors'
:
function
(
assert
,
beforeExit
)
{
'sync: errors'
:
function
(
beforeExit
)
{
var
testIsFinished
=
false
,
sequelizeWithInvalidCredentials
=
new
Sequelize
(
'foo'
,
'bar'
,
'barfoos'
),
Fail
=
sequelizeWithInvalidCredentials
.
define
(
'Fail'
,
{})
...
...
@@ -49,7 +50,7 @@ module.exports = {
})
beforeExit
(
function
()
{
assert
.
equal
(
testIsFinished
,
true
)
})
},
'drop: errors'
:
function
(
assert
,
beforeExit
)
{
'drop: errors'
:
function
(
beforeExit
)
{
var
testIsFinished
=
false
,
sequelizeWithInvalidCredentials
=
new
Sequelize
(
'foo'
,
'bar'
,
'barfoos'
),
Fail
=
sequelizeWithInvalidCredentials
.
define
(
'Fail'
,
{})
...
...
test/Sequelize/sqlQueryFor.js
View file @
30eb3bf
var
Sequelize
=
require
(
__dirname
+
"/../../lib/sequelize/Sequelize"
).
Sequelize
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
var
assert
=
require
(
"assert"
)
module
.
exports
=
{
'sqlQueryFor: create'
:
function
(
assert
)
{
'sqlQueryFor: create'
:
function
()
{
var
query
=
Sequelize
.
sqlQueryFor
(
'create'
,
{
table
:
'Foo'
,
fields
:
'a INT'
})
assert
.
equal
(
query
,
"CREATE TABLE IF NOT EXISTS `Foo` (a INT)"
)
},
'sqlQueryFor: drop'
:
function
(
assert
)
{
'sqlQueryFor: drop'
:
function
()
{
var
query
=
Sequelize
.
sqlQueryFor
(
'drop'
,
{
table
:
'Foo'
})
assert
.
equal
(
query
,
"DROP TABLE IF EXISTS `Foo`"
)
},
'sqlQueryFor: select'
:
function
(
assert
)
{
'sqlQueryFor: select'
:
function
()
{
assert
.
equal
(
Sequelize
.
sqlQueryFor
(
'select'
,
{
table
:
'Foo'
}),
"SELECT * FROM `Foo`"
)
assert
.
equal
(
Sequelize
.
sqlQueryFor
(
'select'
,
{
table
:
'Foo'
,
fields
:
[
'id'
]}),
"SELECT `id` FROM `Foo`"
)
assert
.
equal
(
Sequelize
.
sqlQueryFor
(
'select'
,
{
table
:
'Foo'
,
where
:
{
id
:
1
}}),
"SELECT * FROM `Foo` WHERE `id`=1"
)
...
...
@@ -19,23 +20,23 @@ module.exports = {
assert
.
equal
(
Sequelize
.
sqlQueryFor
(
'select'
,
{
table
:
'Foo'
,
limit
:
1
}),
"SELECT * FROM `Foo` LIMIT 1"
)
assert
.
equal
(
Sequelize
.
sqlQueryFor
(
'select'
,
{
table
:
'Foo'
,
offset
:
10
,
limit
:
1
}),
"SELECT * FROM `Foo` LIMIT 10, 1"
)
},
'sqlQueryFor: insert'
:
function
(
assert
)
{
'sqlQueryFor: insert'
:
function
()
{
var
query
=
Sequelize
.
sqlQueryFor
(
'insert'
,
{
table
:
'Foo'
,
fields
:
[
'foo'
],
values
:
"'bar'"
})
assert
.
equal
(
query
,
"INSERT INTO `Foo` (`foo`) VALUES ('bar')"
)
},
'sqlQueryFor: update'
:
function
(
assert
)
{
'sqlQueryFor: update'
:
function
()
{
var
query
=
Sequelize
.
sqlQueryFor
(
'update'
,
{
table
:
'Foo'
,
values
:
{
foo
:
1
},
id
:
2
})
assert
.
equal
(
query
,
"UPDATE `Foo` SET `foo`=1 WHERE `id`=2"
)
},
'sqlQueryFor: delete'
:
function
(
assert
)
{
'sqlQueryFor: delete'
:
function
()
{
var
query
=
Sequelize
.
sqlQueryFor
(
'delete'
,
{
table
:
'Foo'
,
where
:
{
id
:
2
}})
assert
.
equal
(
query
,
"DELETE FROM `Foo` WHERE `id`=2 LIMIT 1"
)
},
'sqlQueryFor: delete without limit'
:
function
(
assert
)
{
'sqlQueryFor: delete without limit'
:
function
()
{
var
query
=
Sequelize
.
sqlQueryFor
(
'delete'
,
{
table
:
'Foo'
,
where
:
{
id
:
2
},
limit
:
null
})
assert
.
equal
(
query
,
"DELETE FROM `Foo` WHERE `id`=2"
)
},
'sqlQueryFor: delete with limit'
:
function
(
assert
)
{
'sqlQueryFor: delete with limit'
:
function
()
{
var
query
=
Sequelize
.
sqlQueryFor
(
'delete'
,
{
table
:
'Foo'
,
where
:
{
id
:
2
},
limit
:
10
})
assert
.
equal
(
query
,
"DELETE FROM `Foo` WHERE `id`=2 LIMIT 10"
)
}
...
...
test/Table/associations.js
View file @
30eb3bf
var
Sequelize
=
require
(
__dirname
+
"/../../lib/sequelize/Sequelize"
).
Sequelize
var
s
=
new
Sequelize
(
'sequelize_test'
,
'root'
,
null
,
{
disableLogging
:
true
})
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
var
assert
=
require
(
"assert"
)
module
.
exports
=
{
'hasMany'
:
function
(
assert
)
{
'hasMany'
:
function
()
{
var
HasManyBlubb
=
s
.
define
(
'HasManyBlubb'
,
{})
Day
.
hasMany
(
'HasManyBlubbs'
,
HasManyBlubb
)
assert
.
isDefined
(
new
Day
({
name
:
''
}).
getHasManyBlubbs
)
},
'hasMany: set association'
:
function
(
assert
,
beforeExit
)
{
'hasMany: set association'
:
function
(
beforeExit
)
{
var
assoc
=
null
var
Character
=
s
.
define
(
'Character'
,
{})
var
Word
=
s
.
define
(
'Word'
,
{})
...
...
@@ -37,7 +38,7 @@ module.exports = {
assert
.
equal
(
assoc
.
length
,
2
)
})
},
'hasOne'
:
function
(
assert
)
{
'hasOne'
:
function
()
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'root'
,
null
,
{
disableLogging
:
true
})
var
Day
=
s
.
define
(
'Day2'
,
{
name
:
Sequelize
.
TEXT
})
var
HasOneBlubb
=
s
.
define
(
'HasOneBlubb'
,
{})
...
...
@@ -45,7 +46,7 @@ module.exports = {
assert
.
isDefined
(
Day
.
prototype
.
getHasOneBlubb
)
},
'hasOne set association'
:
function
(
assert
,
beforeExit
)
{
'hasOne set association'
:
function
(
beforeExit
)
{
var
s2
=
new
Sequelize
(
'sequelize_test'
,
'root'
,
null
,
{
disableLogging
:
true
})
var
Task
=
s2
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
var
Deadline
=
s2
.
define
(
'Deadline'
,
{
date
:
Sequelize
.
DATE
})
...
...
@@ -63,18 +64,18 @@ module.exports = {
})
beforeExit
(
function
()
{
assert
.
isNotNull
(
assert
Me
)
assert
.
eql
(
assert
Me
,
deadline
)
assert
.
isNotNull
(
Me
)
assert
.
eql
(
Me
,
deadline
)
})
},
'belongsTo'
:
function
(
assert
)
{
'belongsTo'
:
function
()
{
var
BelongsToBlubb
=
s
.
define
(
'BelongsToBlubb'
,
{})
var
Day
=
s
.
define
(
'Day2'
,
{
name
:
Sequelize
.
TEXT
})
var
assoc
=
Day
.
hasOne
(
'asd'
,
BelongsToBlubb
)
Day
.
belongsTo
(
'BelongsToBlubb'
,
BelongsToBlubb
,
assoc
)
assert
.
isDefined
(
new
Day
({
name
:
''
}).
getBelongsToBlubb
)
},
'belongsTo: set association'
:
function
(
assert
,
beforeExit
)
{
'belongsTo: set association'
:
function
(
beforeExit
)
{
var
s2
=
new
Sequelize
(
'sequelize_test'
,
'root'
,
null
,
{
disableLogging
:
true
})
var
Task
=
s2
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
var
Deadline
=
s2
.
define
(
'Deadline'
,
{
date
:
Sequelize
.
DATE
})
...
...
test/Table/basics.js
View file @
30eb3bf
var
Sequelize
=
require
(
__dirname
+
"/../../lib/sequelize/Sequelize"
).
Sequelize
var
s
=
new
Sequelize
(
'sequelize_test'
,
'root'
,
null
,
{
disableLogging
:
true
})
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
var
assert
=
require
(
"assert"
)
module
.
exports
=
{
'constructor'
:
function
(
assert
)
{
'constructor'
:
function
()
{
assert
.
eql
(
Day
.
associations
,
[])
assert
.
eql
(
Day
.
attributes
,
{
"name"
:
{
type
:
"TEXT"
},
"createdAt"
:
{
type
:
"DATETIME"
,
allowNull
:
false
},
"updatedAt"
:
{
type
:
"DATETIME"
,
allowNull
:
false
}})
assert
.
eql
(
Day
.
tableName
,
'Days'
)
},
'new'
:
function
(
assert
)
{
'new'
:
function
()
{
var
day
=
new
Day
({
name
:
'asd'
})
assert
.
isNull
(
day
.
id
)
assert
.
eql
(
day
.
table
,
Day
)
assert
.
eql
(
day
.
name
,
'asd'
)
assert
.
isUndefined
(
new
Day
({
name
:
'asd'
,
bla
:
'foo'
}).
bla
)
},
'sync should return the table class'
:
function
(
assert
,
beforeExit
)
{
'sync should return the table class'
:
function
(
beforeExit
)
{
var
toBeTested
=
null
Day
.
sync
(
function
(
_Day
)
{
toBeTested
=
_Day
})
beforeExit
(
function
()
{
assert
.
eql
(
toBeTested
,
Day
)
})
},
'drop should return the table class'
:
function
(
assert
,
beforeExit
)
{
'drop should return the table class'
:
function
(
beforeExit
)
{
var
toBeTested
=
null
Day
.
drop
(
function
(
_Day
)
{
toBeTested
=
_Day
})
beforeExit
(
function
()
{
assert
.
eql
(
toBeTested
,
Day
)
})
},
'sqlResultToObject returns the correct object'
:
function
(
assert
)
{
'sqlResultToObject returns the correct object'
:
function
()
{
var
SqlResultToObjectTest
=
s
.
define
(
'SqlResultToObject'
,
{
name
:
Sequelize
.
STRING
})
var
toBeTested
=
SqlResultToObjectTest
.
sqlResultToObject
({
id
:
1
,
...
...
@@ -35,14 +36,14 @@ module.exports = {
assert
.
equal
(
toBeTested
.
id
,
1
)
assert
.
equal
(
toBeTested
.
name
,
'foo'
)
},
'identifier'
:
function
(
assert
)
{
'identifier'
:
function
()
{
assert
.
equal
(
s
.
define
(
'Identifier'
,
{}).
identifier
,
'identifierId'
)
},
'values'
:
function
(
assert
)
{
'values'
:
function
()
{
var
day
=
new
Day
({
name
:
's'
})
assert
.
eql
(
day
.
values
,
{
name
:
"s"
,
createdAt
:
null
,
updatedAt
:
null
})
},
'default values'
:
function
(
assert
)
{
'default values'
:
function
()
{
var
DefaultTest
=
s
.
define
(
"DefaultTest"
,
{
aString
:
{
type
:
Sequelize
.
STRING
,
allowNull
:
false
,
default
:
'woot'
},
aNumber
:
{
type
:
Sequelize
.
INTEGER
,
allowNull
:
true
},
...
...
test/Table/databaseAccess.js
View file @
30eb3bf
var
Sequelize
=
require
(
__dirname
+
"/../../lib/sequelize/Sequelize"
).
Sequelize
var
s
=
new
Sequelize
(
'sequelize_test'
,
'root'
,
null
,
{
disableLogging
:
true
})
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
var
assert
=
require
(
"assert"
)
module
.
exports
=
{
'save should set the id of a newly created object'
:
function
(
assert
,
beforeExit
)
{
'save should set the id of a newly created object'
:
function
(
beforeExit
)
{
var
subject
=
null
var
SaveTest
=
s
.
define
(
'SaveTest'
,
{
name
:
Sequelize
.
STRING
})
SaveTest
.
drop
(
function
(){
...
...
@@ -18,7 +19,7 @@ module.exports = {
assert
.
isNotNull
(
subject
.
id
)
})
},
'updateAttributes should update available attributes'
:
function
(
assert
,
beforeExit
)
{
'updateAttributes should update available attributes'
:
function
(
beforeExit
)
{
var
subject
=
null
var
UpdateMe
=
s
.
define
(
'UpdateMe'
,
{
name
:
Sequelize
.
STRING
})
Sequelize
.
chainQueries
([{
drop
:
UpdateMe
},
{
sync
:
UpdateMe
}],
function
()
{
...
...
@@ -35,7 +36,7 @@ module.exports = {
assert
.
isUndefined
(
subject
.
foo
)
})
},
'destroy should make the object unavailable'
:
function
(
assert
,
beforeExit
)
{
'destroy should make the object unavailable'
:
function
(
beforeExit
)
{
var
subject
=
1
var
UpdateAttributesTest
=
s
.
define
(
'UpdateAttributeTest'
,
{
name
:
Sequelize
.
STRING
})
Sequelize
.
chainQueries
([{
drop
:
UpdateAttributesTest
},
{
sync
:
UpdateAttributesTest
}],
function
()
{
...
...
@@ -51,7 +52,7 @@ module.exports = {
assert
.
isNull
(
subject
)
})
},
'boolean ==> save'
:
function
(
assert
,
beforeExit
)
{
'boolean ==> save'
:
function
(
beforeExit
)
{
var
BooleanTest
=
s
.
define
(
"BooleanTest"
,
{
flag
:
Sequelize
.
BOOLEAN
})
var
testIsFinished
=
false
BooleanTest
.
sync
(
function
()
{
...
...
@@ -65,7 +66,7 @@ module.exports = {
})
beforeExit
(
function
()
{
assert
.
equal
(
true
,
testIsFinished
)
})
},
'sync ==> failure'
:
function
(
assert
,
beforeExit
)
{
'sync ==> failure'
:
function
(
beforeExit
)
{
var
testIsFinished
=
false
,
sequelizeWithInvalidCredentials
=
new
Sequelize
(
'foo'
,
'bar'
,
'barfoos'
),
Fail
=
sequelizeWithInvalidCredentials
.
define
(
'Fail'
,
{})
...
...
@@ -77,7 +78,7 @@ module.exports = {
})
beforeExit
(
function
()
{
assert
.
equal
(
testIsFinished
,
true
)
})
},
'drop ==> failure'
:
function
(
assert
,
beforeExit
)
{
'drop ==> failure'
:
function
(
beforeExit
)
{
var
testIsFinished
=
false
,
sequelizeWithInvalidCredentials
=
new
Sequelize
(
'foo'
,
'bar'
,
'barfoos'
),
Fail
=
sequelizeWithInvalidCredentials
.
define
(
'Fail'
,
{})
...
...
test/Table/fetchAssociations.js
View file @
30eb3bf
...
...
@@ -3,8 +3,10 @@ var Sequelize = require(__dirname + "/../../lib/sequelize/Sequelize").Sequelize,
Foo
=
s
.
define
(
'Foo'
,
{
name
:
Sequelize
.
TEXT
}),
Bar
=
s
.
define
(
'Bar'
,
{
nr
:
Sequelize
.
INTEGER
})
var
assert
=
require
(
"assert"
)
module
.
exports
=
{
'should have no fetchedAssociations first'
:
function
(
assert
,
beforeExit
)
{
'should have no fetchedAssociations first'
:
function
(
beforeExit
)
{
var
allowExit
=
false
Foo
.
hasMany
(
'bars'
,
Bar
,
'foos'
)
...
...
@@ -18,7 +20,7 @@ module.exports = {
beforeExit
(
function
()
{
assert
.
eql
(
allowExit
,
true
)
})
},
'should have an empty array for each table association'
:
function
(
assert
,
beforeExit
)
{
'should have an empty array for each table association'
:
function
(
beforeExit
)
{
var
allowExit
=
false
Foo
.
hasMany
(
'bars'
,
Bar
,
'foos'
)
...
...
test/Table/finder.js
View file @
30eb3bf
var
Sequelize
=
require
(
__dirname
+
"/../../lib/sequelize/Sequelize"
).
Sequelize
var
s
=
new
Sequelize
(
'sequelize_test'
,
'root'
,
null
,
{
disableLogging
:
true
})
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
var
assert
=
require
(
"assert"
)
module
.
exports
=
{
'findAll should return all items as class objects'
:
function
(
assert
,
beforeExit
)
{
'findAll should return all items as class objects'
:
function
(
beforeExit
)
{
var
allFindAllTestItems
=
null
var
FindAllTest
=
s
.
define
(
'FindAllTest'
,
{})
...
...
@@ -22,7 +23,7 @@ module.exports = {
})
})
},
'find returns the correct item'
:
function
(
assert
,
beforeExit
)
{
'find returns the correct item'
:
function
(
beforeExit
)
{
var
item
=
null
var
itemToMatch
=
null
var
FindTest
=
s
.
define
(
'FindTest'
,
{
name
:
Sequelize
.
STRING
})
...
...
@@ -44,7 +45,7 @@ module.exports = {
assert
.
equal
(
itemToMatch
.
name
,
item
.
name
)
})
},
'find returns data in correct attributes'
:
function
(
assert
,
beforeExit
)
{
'find returns data in correct attributes'
:
function
(
beforeExit
)
{
var
assertMe
=
null
var
FindMeNow
=
s
.
define
(
'FindMeNow'
,
{
title
:
Sequelize
.
STRING
,
content
:
Sequelize
.
TEXT
})
FindMeNow
.
drop
(
function
()
{
...
...
@@ -55,9 +56,9 @@ module.exports = {
})
})
beforeExit
(
function
()
{
assert
.
isNotNull
(
assert
Me
)
assert
.
equal
(
assert
Me
.
title
,
'a title'
)
assert
.
equal
(
assert
Me
.
content
,
'a content'
)
assert
.
isNotNull
(
Me
)
assert
.
equal
(
Me
.
title
,
'a title'
)
assert
.
equal
(
Me
.
content
,
'a content'
)
})
}
}
\ No newline at end of file
test/Table/prepareAssociations.js
View file @
30eb3bf
var
Sequelize
=
require
(
__dirname
+
"/../../lib/sequelize/Sequelize"
).
Sequelize
var
s
=
new
Sequelize
(
'sequelize_test'
,
'root'
,
null
,
{
disableLogging
:
true
})
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
var
assert
=
require
(
"assert"
)
module
.
exports
=
{
'prepareAssociations belongsTo'
:
function
(
assert
)
{
'prepareAssociations belongsTo'
:
function
()
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'root'
,
null
,
{
disableLogging
:
true
})
var
Me
=
s
.
define
(
'Me'
,
{})
var
You
=
s
.
define
(
'You'
,
{})
...
...
@@ -17,7 +18,7 @@ module.exports = {
assert
.
isDefined
(
You
.
attributes
.
meId
)
assert
.
isNotNull
(
You
.
attributes
.
meId
)
},
'prepareAssociations hasMany'
:
function
(
assert
)
{
'prepareAssociations hasMany'
:
function
()
{
var
House
=
s
.
define
(
'House'
,
{})
var
Person
=
s
.
define
(
'Person'
,
{})
...
...
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