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 6f168944
authored
Sep 08, 2015
by
Clement Teule
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor the unit tests to be less waterfall.
1 parent
34f0eacb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
80 deletions
test/integration/instance.test.js
test/integration/instance.test.js
View file @
6f16894
...
...
@@ -520,28 +520,27 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
Player
.
hasOne
(
Shoe
);
Shoe
.
belongsTo
(
Player
);
return
Player
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Shoe
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Shoe
.
create
({
brand
:
'the brand'
}).
then
(
function
(
team
)
{
return
Player
.
create
({
name
:
'the player'
}).
then
(
function
(
player
)
{
return
player
.
setShoe
(
team
).
then
(
function
()
{
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Shoe
.
create
({
brand
:
'the brand'
,
Player
:
{
name
:
'the player'
}
},
{
include
:
[
Player
]});
}).
then
(
function
(
shoe
)
{
return
Player
.
findOne
({
where
:
{
id
:
p
layer
.
id
},
where
:
{
id
:
shoe
.
P
layer
.
id
},
include
:
[
Shoe
]
}).
then
(
function
(
lePlayer
)
{
expect
(
lePlayer
.
Shoe
).
not
.
to
.
be
.
null
;
return
lePlayer
.
Shoe
.
destroy
().
then
(
function
()
{
return
lePlayer
.
reload
().
then
(
function
(
lePlayer
)
{
return
lePlayer
.
Shoe
.
destroy
().
return
(
lePlayer
);
}).
then
(
function
(
lePlayer
)
{
return
lePlayer
.
reload
();
}).
then
(
function
(
lePlayer
)
{
expect
(
lePlayer
.
Shoe
).
to
.
be
.
null
;
});
});
});
});
});
});
});
});
});
it
(
'should set an association to empty after all deletion, 1-N'
,
function
()
{
var
Team
=
this
.
sequelize
.
define
(
'Team'
,
{
name
:
DataTypes
.
STRING
})
...
...
@@ -550,95 +549,60 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
Team
.
hasMany
(
Player
);
Player
.
belongsTo
(
Team
);
return
Team
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Player
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Team
.
create
({
name
:
'the team'
}).
then
(
function
(
team
)
{
return
Player
.
create
({
name
:
'the player1'
}).
then
(
function
(
player1
)
{
return
Player
.
create
({
name
:
'the player2'
}).
then
(
function
(
player2
)
{
return
team
.
setPlayers
([
player1
,
player2
]).
then
(
function
()
{
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Team
.
create
({
name
:
'the team'
,
Players
:
[{
name
:
'the player1'
},
{
name
:
'the player2'
}]
},
{
include
:
[
Player
]});
}).
then
(
function
(
team
)
{
return
Team
.
findOne
({
where
:
{
id
:
team
.
id
},
include
:
[
Player
]
}).
then
(
function
(
leTeam
)
{
expect
(
leTeam
.
Players
).
not
.
to
.
be
.
empty
;
return
player1
.
destroy
().
then
(
function
()
{
return
player2
.
destroy
().
then
(
function
()
{
return
leTeam
.
reload
().
then
(
function
(
leTeam
)
{
return
leTeam
.
Players
[
1
].
destroy
().
then
(
function
()
{
return
leTeam
.
Players
[
0
].
destroy
();
}).
return
(
leTeam
);
}).
then
(
function
(
leTeam
)
{
return
leTeam
.
reload
();
}).
then
(
function
(
leTeam
)
{
expect
(
leTeam
.
Players
).
to
.
be
.
empty
;
});
});
});
});
});
});
});
});
});
});
});
it
(
'should update the associations after
first element deleted, 1-N
'
,
function
()
{
it
(
'should update the associations after
one element deleted
'
,
function
()
{
var
Team
=
this
.
sequelize
.
define
(
'Team'
,
{
name
:
DataTypes
.
STRING
})
,
Player
=
this
.
sequelize
.
define
(
'Player'
,
{
name
:
DataTypes
.
STRING
});
Team
.
hasMany
(
Player
);
Player
.
belongsTo
(
Team
);
return
Team
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Player
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Team
.
create
({
name
:
'the team'
}).
then
(
function
(
team
)
{
return
Player
.
create
({
name
:
'the player1'
}).
then
(
function
(
player1
)
{
return
Player
.
create
({
name
:
'the player2'
}).
then
(
function
(
player2
)
{
return
team
.
setPlayers
([
player1
,
player2
]).
then
(
function
()
{
return
Team
.
findOne
({
where
:
{
id
:
team
.
id
},
include
:
[
Player
]
}).
then
(
function
(
leTeam
)
{
expect
(
leTeam
.
Players
).
to
.
have
.
length
(
2
);
return
player2
.
destroy
().
then
(
function
()
{
return
leTeam
.
reload
().
then
(
function
(
leTeam
)
{
expect
(
leTeam
.
Players
).
to
.
have
.
length
(
1
);
expect
(
leTeam
.
Players
[
0
].
name
).
to
.
equal
(
'the player1'
);
});
});
});
});
});
});
});
});
});
});
it
(
'should update the associations after not-first element deleted, 1-N'
,
function
()
{
var
Team
=
this
.
sequelize
.
define
(
'Team'
,
{
name
:
DataTypes
.
STRING
})
,
Player
=
this
.
sequelize
.
define
(
'Player'
,
{
name
:
DataTypes
.
STRING
});
Team
.
hasMany
(
Player
);
Player
.
belongsTo
(
Team
);
return
Team
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Player
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Team
.
create
({
name
:
'the team'
}).
then
(
function
(
team
)
{
return
Player
.
create
({
name
:
'the player1'
}).
then
(
function
(
player1
)
{
return
Player
.
create
({
name
:
'the player2'
}).
then
(
function
(
player2
)
{
return
team
.
setPlayers
([
player1
,
player2
]).
then
(
function
()
{
return
this
.
sequelize
.
sync
({
force
:
true
}).
then
(
function
()
{
return
Team
.
create
({
name
:
'the team'
,
Players
:
[{
name
:
'the player1'
},
{
name
:
'the player2'
}]
},
{
include
:
[
Player
]});
}).
then
(
function
(
team
)
{
return
Team
.
findOne
({
where
:
{
id
:
team
.
id
},
include
:
[
Player
]
}).
then
(
function
(
leTeam
)
{
expect
(
leTeam
.
Players
).
to
.
have
.
length
(
2
);
return
player1
.
destroy
().
then
(
function
()
{
return
leTeam
.
reload
().
then
(
function
(
leTeam
)
{
return
leTeam
.
Players
[
0
].
destroy
().
return
(
leTeam
);
}).
then
(
function
(
leTeam
)
{
return
leTeam
.
reload
();
}).
then
(
function
(
leTeam
)
{
expect
(
leTeam
.
Players
).
to
.
have
.
length
(
1
);
expect
(
leTeam
.
Players
[
0
].
name
).
to
.
equal
(
'the player2'
);
});
});
});
});
});
});
});
});
});
});
...
...
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