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 957893c6
authored
Nov 14, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved association specs to own file
1 parent
56237112
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
72 deletions
spec/associations.has-many.spec.js
spec/model.spec.js
spec/associations.has-many.spec.js
0 → 100644
View file @
957893c
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
(
'HasMany'
,
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
)
})
})
describe
(
'addModel / getModel'
,
function
()
{
var
user
=
null
,
task
=
null
beforeEach
(
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
all
().
on
(
'success'
,
function
(
_users
)
{
Task
.
all
().
on
(
'success'
,
function
(
_tasks
)
{
user
=
_users
[
0
]
task
=
_tasks
[
0
]
done
()
})
})
})
})
it
(
'should correctly add an association to the model'
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
user
.
getTasks
().
on
(
'success'
,
function
(
_tasks
)
{
expect
(
_tasks
.
length
).
toEqual
(
0
)
user
.
addTask
(
task
).
on
(
'success'
,
function
()
{
user
.
getTasks
().
on
(
'success'
,
function
(
_tasks
)
{
expect
(
_tasks
.
length
).
toEqual
(
1
)
done
()
})
})
})
})
})
})
describe
(
'removeModel'
,
function
()
{
var
user
=
null
,
tasks
=
null
beforeEach
(
function
()
{
Helpers
.
async
(
function
(
done
)
{
User
.
all
().
on
(
'success'
,
function
(
users
)
{
Task
.
all
().
on
(
'success'
,
function
(
_tasks
)
{
user
=
users
[
0
]
tasks
=
_tasks
done
()
})
})
})
})
it
(
"should correctly remove associated objects"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
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
()
})
})
})
})
})
})
})
})
})
spec/model.spec.js
View file @
957893c
...
@@ -4,75 +4,7 @@ var config = require("./config/config")
...
@@ -4,75 +4,7 @@ var config = require("./config/config")
,
Helpers
=
new
(
require
(
"./config/helpers"
))(
sequelize
)
,
Helpers
=
new
(
require
(
"./config/helpers"
))(
sequelize
)
describe
(
'Model'
,
function
()
{
describe
(
'Model'
,
function
()
{
beforeEach
(
function
()
{
Helpers
.
sync
()
})
describe
(
'Validations'
,
function
()
{
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
()
})
})
})
})
})
})
})
})
})
})
describe
(
'Validations'
,
function
()
{
var
checks
=
{
var
checks
=
{
is
:
{
is
:
{
spec
:
{
args
:
[
/
[
a-z
]
/
,
'i'
]
},
spec
:
{
args
:
[
/
[
a-z
]
/
,
'i'
]
},
...
@@ -285,7 +217,6 @@ describe('Validations', function() {
...
@@ -285,7 +217,6 @@ describe('Validations', function() {
it
(
'should correctly validate using custom validation methods'
,
function
()
{
it
(
'should correctly validate using custom validation methods'
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
Helpers
.
async
(
function
(
done
)
{
User
=
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
User
=
sequelize
.
define
(
'User'
+
Math
.
random
(),
{
name
:
{
name
:
{
type
:
Sequelize
.
STRING
,
type
:
Sequelize
.
STRING
,
...
@@ -315,6 +246,5 @@ describe('Validations', function() {
...
@@ -315,6 +246,5 @@ describe('Validations', function() {
done
();
done
();
});
});
});
});
})
})
})
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