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 313c6969
authored
Aug 07, 2010
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests are now using expresso 0.6.1
1 parent
2d55a45b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
22 deletions
test/SequelizeHelperTest.js
test/SequelizeTableTest.js
test/SequelizeTest.js
test/SequelizeHelperTest.js
View file @
313c696
...
...
@@ -4,7 +4,7 @@ var h = SequelizeHelper
module
.
exports
=
{
'log should be defined'
:
function
(
assert
)
{
assert
.
isNotNull
(
h
.
log
)
assert
.
is
NotUnd
efined
(
h
.
log
)
assert
.
is
D
efined
(
h
.
log
)
},
'evaluateTemplate'
:
function
(
assert
)
{
...
...
test/SequelizeTableTest.js
View file @
313c696
...
...
@@ -25,6 +25,7 @@ module.exports = {
assert
.
equal
(
Foo
.
isCrossAssociatedWith
(
Day
),
true
)
},
'prepareAssociations belongsTo'
:
function
(
assert
)
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
,
{
disableLogging
:
true
})
var
Me
=
s
.
define
(
'Me'
,
{})
var
You
=
s
.
define
(
'You'
,
{})
You
.
belongsTo
(
'me'
,
Me
)
...
...
@@ -33,7 +34,7 @@ module.exports = {
You
.
prepareAssociations
()
assert
.
includes
(
SequelizeHelper
.
Hash
.
keys
(
You
.
attributes
),
'meId'
)
assert
.
is
NotUnd
efined
(
You
.
attributes
.
meId
)
assert
.
is
D
efined
(
You
.
attributes
.
meId
)
assert
.
isNotNull
(
You
.
attributes
.
meId
)
},
'prepareAssociations hasOne'
:
function
(
assert
)
{
...
...
@@ -45,7 +46,7 @@ module.exports = {
You
.
prepareAssociations
()
assert
.
includes
(
SequelizeHelper
.
Hash
.
keys
(
Me
.
attributes
),
'you2Id'
)
assert
.
is
NotUnd
efined
(
Me
.
attributes
.
you2Id
)
assert
.
is
D
efined
(
Me
.
attributes
.
you2Id
)
assert
.
isNotNull
(
Me
.
attributes
.
you2Id
)
},
'prepareAssociations hasMany'
:
function
(
assert
)
{
...
...
@@ -60,7 +61,7 @@ module.exports = {
assert
.
isUndefined
(
ManyToManyPart1
.
attributes
.
manyToManyPart2Id
)
assert
.
isUndefined
(
ManyToManyPart2
.
attributes
.
manyToManyPart1Id
)
assert
.
is
NotUnd
efined
(
s
.
tables
.
ManyToManyPart1sManyToManyPart2s
)
assert
.
is
D
efined
(
s
.
tables
.
ManyToManyPart1sManyToManyPart2s
)
},
'sync should return the table class'
:
function
(
assert
,
beforeExit
)
{
var
toBeTested
=
null
...
...
@@ -113,6 +114,22 @@ module.exports = {
assert
.
equal
(
itemToMatch
.
name
,
item
.
name
)
})
},
'find returns data in correct attributes'
:
function
(
assert
,
beforeExit
)
{
var
assertMe
=
null
var
FindMeNow
=
s
.
define
(
'FindMeNow'
,
{
title
:
Sequelize
.
STRING
,
content
:
Sequelize
.
TEXT
})
FindMeNow
.
drop
(
function
()
{
FindMeNow
.
sync
(
function
()
{
new
FindMeNow
({
title
:
'a title'
,
content
:
'a content'
}).
save
(
function
(
blubb
)
{
assertMe
=
blubb
})
})
})
beforeExit
(
function
()
{
assert
.
isNotNull
(
assertMe
)
assert
.
equal
(
assertMe
.
title
,
'a title'
)
assert
.
equal
(
assertMe
.
content
,
'a content'
)
})
},
'sqlResultToObject returns the correct object'
:
function
(
assert
)
{
var
SqlResultToObjectTest
=
s
.
define
(
'SqlResultToObject'
,
{
name
:
Sequelize
.
STRING
})
var
toBeTested
=
SqlResultToObjectTest
.
sqlResultToObject
({
...
...
@@ -126,7 +143,7 @@ module.exports = {
'hasMany'
:
function
(
assert
)
{
var
HasManyBlubb
=
s
.
define
(
'HasManyBlubb'
,
{})
Day
.
hasMany
(
'HasManyBlubbs'
,
HasManyBlubb
)
assert
.
is
NotUnd
efined
(
new
Day
({
name
:
''
}).
HasManyBlubbs
)
assert
.
is
D
efined
(
new
Day
({
name
:
''
}).
HasManyBlubbs
)
},
'hasMany: set association'
:
function
(
assert
,
beforeExit
)
{
var
assoc
=
null
...
...
@@ -158,9 +175,11 @@ module.exports = {
})
},
'hasOne'
:
function
(
assert
)
{
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
,
{
disableLogging
:
true
})
var
Day
=
s
.
define
(
'Day2'
,
{
name
:
Sequelize
.
TEXT
})
var
HasOneBlubb
=
s
.
define
(
'HasOneBlubb'
,
{})
Day
.
hasOne
(
'HasOneBlubb'
,
HasOneBlubb
)
assert
.
is
NotUnd
efined
(
new
Day
({
name
:
''
}).
HasOneBlubb
)
assert
.
is
D
efined
(
new
Day
({
name
:
''
}).
HasOneBlubb
)
},
'hasOne set association'
:
function
(
assert
,
beforeExit
)
{
var
s2
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
,
{
disableLogging
:
true
})
...
...
@@ -186,12 +205,13 @@ module.exports = {
'belongsTo'
:
function
(
assert
)
{
var
BelongsToBlubb
=
s
.
define
(
'BelongsToBlubb'
,
{})
Day
.
belongsTo
(
'BelongsToBlubb'
,
BelongsToBlubb
)
assert
.
is
NotUnd
efined
(
new
Day
({
name
:
''
}).
BelongsToBlubb
)
assert
.
is
D
efined
(
new
Day
({
name
:
''
}).
BelongsToBlubb
)
},
'belongsTo: set association'
:
function
(
assert
,
beforeExit
)
{
var
s2
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
,
{
disableLogging
:
tru
e
})
var
s2
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
,
{
disableLogging
:
fals
e
})
var
Task
=
s2
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
})
var
Deadline
=
s2
.
define
(
'Deadline'
,
{
date
:
Sequelize
.
DATE
})
var
allowExit
=
false
Task
.
hasOne
(
'deadline'
,
Deadline
)
Deadline
.
belongsTo
(
'task'
,
Task
)
...
...
@@ -200,13 +220,23 @@ module.exports = {
var
deadline
=
new
Deadline
({
date
:
new
Date
()})
var
assertMe
=
null
Sequelize
.
chainQueries
([{
drop
:
s2
},
{
sync
:
s2
},
{
save
:
task
},
{
save
:
deadline
}],
function
()
{
deadline
.
setTask
(
task
,
function
(
_task
)
{
assertMe
=
_task
})
Sequelize
.
chainQueries
([{
drop
:
s2
},
{
sync
:
s2
}],
function
()
{
task
.
save
(
function
()
{
deadline
.
save
(
function
()
{
SequelizeHelper
.
log
(
'drin'
)
assert
.
isDefined
(
deadline
.
id
)
assert
.
isNotNull
(
deadline
.
id
)
deadline
.
setTask
(
task
,
function
(
_task
)
{
assert
.
isNotNull
(
_task
)
assert
.
eql
(
_task
.
id
,
task
.
id
)
allowExit
=
true
})
})
})
})
beforeExit
(
function
()
{
assert
.
isNotNull
(
assertMe
)
assert
.
eql
(
assertMe
.
id
,
task
.
id
)
assert
.
equal
(
allowExit
,
true
)
})
},
'identifier'
:
function
(
assert
)
{
...
...
@@ -233,16 +263,17 @@ module.exports = {
},
'updateAttributes should update available attributes'
:
function
(
assert
,
beforeExit
)
{
var
subject
=
null
Sequelize
.
chainQueries
([{
drop
:
Day
},
{
sync
:
Day
}],
function
()
{
new
Day
({
name
:
'Monday'
}).
save
(
function
(
day
)
{
day
.
updateAttributes
({
name
:
'Sunday'
,
foo
:
'bar'
},
function
(
day
)
{
subject
=
day
var
UpdateMe
=
s
.
define
(
'UpdateMe'
,
{
name
:
Sequelize
.
STRING
})
Sequelize
.
chainQueries
([{
drop
:
UpdateMe
},
{
sync
:
UpdateMe
}],
function
()
{
new
UpdateMe
({
name
:
'Monday'
}).
save
(
function
(
u
)
{
u
.
updateAttributes
({
name
:
'Sunday'
,
foo
:
'bar'
},
function
(
u
)
{
subject
=
u
})
})
})
beforeExit
(
function
()
{
assert
.
isNotNull
(
subject
)
assert
.
equal
(
subject
.
name
,
'Sunday'
)
assert
.
isUndefined
(
subject
.
foo
)
})
...
...
test/SequelizeTest.js
View file @
313c696
...
...
@@ -4,11 +4,11 @@ var s = new Sequelize('sequelize_test', 'test', 'test')
module
.
exports
=
{
'test constants'
:
function
(
assert
)
{
assert
.
is
NotUnd
efined
(
Sequelize
.
STRING
)
assert
.
is
D
efined
(
Sequelize
.
STRING
)
assert
.
isNotNull
(
Sequelize
.
STRING
)
assert
.
is
NotUnd
efined
(
Sequelize
.
TEXT
)
assert
.
is
D
efined
(
Sequelize
.
TEXT
)
assert
.
isNotNull
(
Sequelize
.
TEXT
)
assert
.
is
NotUnd
efined
(
Sequelize
.
INTEGER
)
assert
.
is
D
efined
(
Sequelize
.
INTEGER
)
assert
.
isNotNull
(
Sequelize
.
INTEGER
)
},
'the constructor sets config correctly'
:
function
(
assert
){
...
...
@@ -17,7 +17,8 @@ module.exports = {
assert
.
equal
(
s
.
config
.
password
,
'test'
)
},
'the constructor initializes empty tables hash'
:
function
(
assert
)
{
assert
.
isNotUndefined
(
s
.
tables
)
var
s
=
new
Sequelize
(
'sequelize_test'
,
'test'
,
'test'
)
assert
.
isDefined
(
s
.
tables
)
assert
.
isNotNull
(
s
.
tables
)
assert
.
eql
(
s
.
tables
,
{})
},
...
...
@@ -27,7 +28,7 @@ module.exports = {
},
'define should store attributes'
:
function
(
assert
)
{
var
Day
=
s
.
define
(
'Day'
,
{
name
:
Sequelize
.
TEXT
})
assert
.
is
NotUnd
efined
(
Day
.
attributes
)
assert
.
is
D
efined
(
Day
.
attributes
)
assert
.
isNotNull
(
Day
.
attributes
)
assert
.
eql
(
Day
.
attributes
,
{
name
:
Sequelize
.
TEXT
,
createdAt
:
"DATETIME NOT NULL"
,
updatedAt
:
"DATETIME NOT NULL"
})
},
...
...
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