Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
8b426b63
Commit
8b426b63
authored
Nov 13, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete the fork network when removing the last membership
parent
4aa18590
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
0 deletions
+36
-0
app/models/fork_network_member.rb
app/models/fork_network_member.rb
+10
-0
spec/factories/fork_network_members.rb
spec/factories/fork_network_members.rb
+8
-0
spec/models/fork_network_member_spec.rb
spec/models/fork_network_member_spec.rb
+18
-0
No files found.
app/models/fork_network_member.rb
View file @
8b426b63
...
...
@@ -4,4 +4,14 @@ class ForkNetworkMember < ActiveRecord::Base
belongs_to
:forked_from_project
,
class_name:
'Project'
validates
:fork_network
,
:project
,
presence:
true
after_destroy
:cleanup_fork_network
private
def
cleanup_fork_network
# Explicitly using `#count` makes sure we have the correct number if the
# relation was loaded in the fork_network.
fork_network
.
destroy
if
fork_network
.
fork_network_members
.
count
==
0
end
end
spec/factories/fork_network_members.rb
0 → 100644
View file @
8b426b63
FactoryGirl
.
define
do
factory
:fork_network_member
do
association
:project
association
:fork_network
forked_from_project
{
fork_network
.
root_project
}
end
end
spec/models/fork_network_member_spec.rb
View file @
8b426b63
...
...
@@ -5,4 +5,22 @@ describe ForkNetworkMember do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:fork_network
)
}
end
describe
'destroying a ForkNetworkMember'
do
let
(
:fork_network_member
)
{
create
(
:fork_network_member
)
}
let
(
:fork_network
)
{
fork_network_member
.
fork_network
}
it
'removes the fork network if it was the last member'
do
fork_network
.
fork_network_members
.
destroy_all
expect
(
ForkNetwork
.
count
).
to
eq
(
0
)
end
it
'does not destroy the fork network if there are members left'
do
fork_network_member
.
destroy!
# The root of the fork network is left
expect
(
ForkNetwork
.
count
).
to
eq
(
1
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment