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 9d1c45bb
authored
Oct 27, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
factories
1 parent
259ee5ba
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
38 deletions
spec/config/factories.js
spec/config/helpers.js
spec/model-definition.spec.js
spec/config/factories.js
0 → 100644
View file @
9d1c45b
var
Factories
=
module
.
exports
=
function
(
helpers
)
{
this
.
helpers
=
helpers
this
.
sequelize
=
this
.
helpers
.
sequelize
}
Factories
.
prototype
.
Model
=
function
(
modelName
,
options
,
callback
,
count
)
{
count
=
count
||
1
var
self
=
this
this
.
sequelize
.
modelManager
.
getModel
(
modelName
).
create
(
options
).
on
(
'success'
,
function
(
model
){
--
count
?
self
.
Model
(
modelName
,
options
,
callback
,
count
)
:
callback
(
model
)
}).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
}
Factories
.
prototype
.
User
=
function
(
options
,
callback
,
count
)
{
this
.
Model
(
'User'
,
options
,
callback
,
count
)
}
spec/config/helpers.js
View file @
9d1c45b
var
Helpers
=
module
.
exports
=
{
async
:
function
(
fct
)
{
var
done
=
false
runs
(
function
()
{
fct
(
function
()
{
return
done
=
true
})
})
waitsFor
(
function
(){
return
done
})
}
var
Helpers
=
module
.
exports
=
function
(
sequelize
)
{
this
.
sequelize
=
sequelize
this
.
Factories
=
new
(
require
(
"./factories"
))(
this
)
}
Helpers
.
prototype
.
sync
=
function
()
{
var
self
=
this
this
.
async
(
function
(
done
)
{
self
.
sequelize
.
sync
({
force
:
true
})
.
on
(
'success'
,
done
)
.
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
}
Helpers
.
prototype
.
drop
=
function
()
{
var
self
=
this
this
.
async
(
function
(
done
)
{
self
.
sequelize
.
drop
()
.
on
(
'success'
,
done
)
.
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
}
Helpers
.
prototype
.
async
=
function
(
fct
)
{
var
done
=
false
runs
(
function
()
{
fct
(
function
()
{
return
done
=
true
})
})
waitsFor
(
function
(){
return
done
})
}
spec/model-definition.spec.js
View file @
9d1c45b
var
config
=
require
(
"./config/config"
)
,
Helpers
=
require
(
"./config/helpers"
)
,
Sequelize
=
require
(
"../index"
)
,
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
Helpers
=
new
(
require
(
"./config/helpers"
))(
sequelize
)
describe
(
'ModelDefinition'
,
function
()
{
var
sequelize
=
new
Sequelize
(
config
.
database
,
config
.
username
,
config
.
password
,
{
logging
:
false
})
,
User
=
sequelize
.
define
(
'User'
,
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
var
User
=
sequelize
.
define
(
'User'
,
{
name
:
Sequelize
.
STRING
,
bio
:
Sequelize
.
TEXT
})
beforeEach
(
function
()
{
Helpers
.
async
(
function
(
done
)
{
sequelize
.
sync
({
force
:
true
}).
on
(
'success'
,
done
).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
})
afterEach
(
function
()
{
Helpers
.
async
(
function
(
done
)
{
sequelize
.
drop
().
on
(
'success'
,
done
).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
})
beforeEach
(
function
()
{
Helpers
.
sync
()
})
afterEach
(
function
()
{
Helpers
.
drop
()
})
//////////// all //////////////
describe
(
'.all'
,
function
()
{
beforeEach
(
function
()
{
var
UserFactory
=
function
(
options
,
callback
,
count
)
{
count
=
count
||
1
User
.
create
(
options
).
on
(
'success'
,
function
(
user
){
--
count
?
UserFactory
(
options
,
callback
,
count
)
:
callback
(
user
)
}).
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
}
Helpers
.
async
(
function
(
done
)
{
UserFactory
({
name
:
'user'
,
bio
:
'foobar'
},
done
,
2
)
})
Helpers
.
async
(
function
(
done
)
{
Helpers
.
Factories
.
User
({
name
:
'user'
,
bio
:
'foobar'
},
done
,
2
)
})
})
it
(
"should return all users"
,
function
()
{
...
...
@@ -52,10 +36,10 @@ describe('ModelDefinition', function() {
it
(
'should allow the creation of an object with options as attribute'
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
var
options
=
JSON
.
stringify
({
foo
:
'bar'
,
bar
:
'foo'
})
Person
.
create
({
name
:
'John Doe'
,
options
:
options
}).
on
(
'success'
,
function
(
person
)
{
Helpers
.
Factories
.
Model
(
'Person'
,
{
name
:
'John Doe'
,
options
:
options
}
,
function
(
person
)
{
expect
(
person
.
options
).
toEqual
(
options
)
done
()
})
.
on
(
'failure'
,
function
(
err
)
{
console
.
log
(
err
)
})
})
})
})
})
...
...
@@ -71,10 +55,7 @@ describe('ModelDefinition', function() {
Table2
.
hasMany
(
Table1
)
it
(
"should create a table wp_table1wp_table2s"
,
function
()
{
var
models
=
sequelize
.
modelManager
.
models
.
filter
(
function
(
model
)
{
return
model
.
tableName
.
indexOf
(
'wp_table1swp_table2s'
)
>
-
1
})
expect
(
models
.
length
).
toBe
(
1
)
expect
(
sequelize
.
modelManager
.
getModel
(
'wp_table1swp_table2s'
)).
toBeDefined
()
})
})
})
...
...
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