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 3e57b469
authored
Nov 11, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed tests
1 parent
cbe4ae7d
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
96 additions
and
86 deletions
spec/config/factories.js
spec/config/helpers.js
spec/model-definition.spec.js → spec/model-factory.spec.js
spec/model.spec.js
test/Model/add-remove-association.js
spec/config/factories.js
View file @
3e57b46
...
@@ -7,15 +7,31 @@ Factories.prototype.Model = function(modelName, options, callback, count) {
...
@@ -7,15 +7,31 @@ Factories.prototype.Model = function(modelName, options, callback, count) {
count
=
count
||
1
count
=
count
||
1
var
self
=
this
var
self
=
this
,
models
=
[]
this
.
helpers
.
async
(
function
(
done
)
{
this
.
helpers
.
async
(
function
(
done
)
{
self
.
sequelize
.
modelManager
.
getModel
(
modelName
).
create
(
options
).
on
(
'success'
,
function
(
model
){
var
Model
=
self
.
sequelize
.
modelManager
.
getModel
(
modelName
)
done
()
--
count
?
self
.
Model
(
modelName
,
options
,
callback
,
count
)
:
(
callback
&&
callback
(
model
))
var
create
=
function
(
cb
)
{
Model
.
create
(
options
).
on
(
'success'
,
function
(
model
)
{
models
.
push
(
model
)
cb
&&
cb
()
}).
on
(
'failure'
,
function
(
err
)
{
}).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
console
.
log
(
err
)
done
()
done
()
})
})
}
var
cb
=
function
()
{
if
(
--
count
)
{
create
(
cb
)
}
else
{
done
()
callback
&&
callback
(
models
)
}
}
create
(
cb
)
})
})
}
}
...
...
spec/config/helpers.js
View file @
3e57b46
Sequelize
=
require
(
"../../index"
)
var
Helpers
=
module
.
exports
=
function
(
sequelize
)
{
var
Helpers
=
module
.
exports
=
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
this
.
sequelize
=
sequelize
this
.
Factories
=
new
(
require
(
"./factories"
))(
this
)
this
.
Factories
=
new
(
require
(
"./factories"
))(
this
)
...
...
spec/model-
definition
.spec.js
→
spec/model-
factory
.spec.js
View file @
3e57b46
...
@@ -33,8 +33,8 @@ describe('ModelFactory', function() {
...
@@ -33,8 +33,8 @@ describe('ModelFactory', function() {
it
(
'should allow the creation of an object with options as attribute'
,
function
()
{
it
(
'should allow the creation of an object with options as attribute'
,
function
()
{
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
})
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
})
Helpers
.
Factories
.
Model
(
'Person'
,
{
name
:
'John Doe'
,
options
:
options
},
function
(
pe
rson
)
{
Helpers
.
Factories
.
Model
(
'Person'
,
{
name
:
'John Doe'
,
options
:
options
},
function
(
pe
ople
)
{
expect
(
pe
rson
.
options
).
toEqual
(
options
)
expect
(
pe
ople
[
0
]
.
options
).
toEqual
(
options
)
})
})
})
})
})
})
...
...
spec/model.spec.js
0 → 100644
View file @
3e57b46
var
config
=
require
(
"./config/config"
)
,
Sequelize
=
require
(
"../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
Helpers
=
new
(
require
(
"./config/helpers"
))(
sequelize
)
describe
(
'Model'
,
function
()
{
beforeEach
(
function
()
{
Helpers
.
sync
()
})
afterEach
(
function
()
{
Helpers
.
drop
()
})
var
User
=
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
name
:
Sequelize
.
STRING
})
,
Task
=
sequelize
.
define
(
'Task'
+
Math
.
random
(),
{
name
:
Sequelize
.
STRING
})
,
users
=
null
,
tasks
=
null
User
.
hasMany
(
Task
,
{
as
:
'Tasks'
})
Task
.
hasMany
(
User
,
{
as
:
'Users'
})
beforeEach
(
function
()
{
Helpers
.
async
(
function
(
_done
)
{
Helpers
.
Factories
.
Model
(
User
.
name
,
{
name
:
'User'
+
Math
.
random
()},
function
(
_users
)
{
users
=
_users
;
_done
()
},
5
)
})
Helpers
.
async
(
function
(
_done
)
{
Helpers
.
Factories
.
Model
(
Task
.
name
,
{
name
:
'Task'
+
Math
.
random
()},
function
(
_tasks
)
{
tasks
=
_tasks
;
_done
()
},
2
)
})
})
it
(
'should correctly add an association to the model'
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
all
().
on
(
'success'
,
function
(
users
)
{
Task
.
all
().
on
(
'success'
,
function
(
tasks
)
{
var
user
=
users
[
0
]
user
.
getTasks
().
on
(
'success'
,
function
(
_tasks
)
{
expect
(
_tasks
.
length
).
toEqual
(
0
)
user
.
addTask
(
tasks
[
0
]).
on
(
'success'
,
function
()
{
user
.
getTasks
().
on
(
'success'
,
function
(
_tasks
)
{
expect
(
_tasks
.
length
).
toEqual
(
1
)
done
()
})
})
})
})
})
})
})
it
(
"should correctly remove associated objects"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
all
().
on
(
'success'
,
function
(
users
)
{
Task
.
all
().
on
(
'success'
,
function
(
tasks
)
{
var
user
=
users
[
0
]
user
.
getTasks
().
on
(
'success'
,
function
(
_tasks
)
{
expect
(
_tasks
.
length
).
toEqual
(
0
)
user
.
setTasks
(
tasks
).
on
(
'success'
,
function
()
{
user
.
getTasks
().
on
(
'success'
,
function
(
_tasks
)
{
expect
(
_tasks
.
length
).
toEqual
(
tasks
.
length
)
user
.
removeTask
(
tasks
[
0
]).
on
(
'success'
,
function
()
{
user
.
getTasks
().
on
(
'success'
,
function
(
_tasks
)
{
expect
(
_tasks
.
length
).
toEqual
(
tasks
.
length
-
1
)
done
()
})
})
})
})
})
})
})
})
})
})
test/Model/add-remove-association.js
deleted
100644 → 0
View file @
cbe4ae7
var
assert
=
require
(
"assert"
)
,
config
=
require
(
"./../config"
)
,
Sequelize
=
require
(
"./../../index"
)
,
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
})
,
chainer
=
new
Sequelize
.
Utils
.
QueryChainer
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
)
})
})
}
module
.
exports
=
{
'it should correctly add an association to the model'
:
function
(
exit
)
{
initialize
({
taskCount
:
5
,
userCount
:
2
},
function
(
Task
,
User
)
{
User
.
all
().
on
(
'success'
,
function
(
users
)
{
Task
.
all
().
on
(
'success'
,
function
(
tasks
)
{
var
user
=
users
[
0
]
user
.
getTasks
().
on
(
'success'
,
function
(
_tasks
)
{
assert
.
eql
(
_tasks
.
length
,
0
)
user
.
addTask
(
tasks
[
0
]).
on
(
'success'
,
function
()
{
user
.
getTasks
().
on
(
'success'
,
function
(
_tasks
)
{
assert
.
eql
(
_tasks
.
length
,
1
)
exit
(
function
(){})
})
})
})
})
})
})
},
'it should correctly remove associated objects'
:
function
(
exit
)
{
initialize
({
taskCount
:
5
,
userCount
:
2
},
function
(
Task
,
User
)
{
User
.
all
().
on
(
'success'
,
function
(
users
)
{
Task
.
all
().
on
(
'success'
,
function
(
tasks
)
{
var
user
=
users
[
0
]
user
.
getTasks
().
on
(
'success'
,
function
(
_tasks
)
{
assert
.
eql
(
_tasks
.
length
,
0
)
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
)
exit
(
function
(){})
})
})
})
})
})
})
})
})
}
}
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