Commit e672ed84 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Nullify pool_repository when a project leaves

Previously the nullification wasn't done, as the only caller would later
destroy the model all together. In
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/9070 this change
was made. This commit is basically a backport before that MR is merged.
parent a996e4e3
...@@ -85,7 +85,11 @@ class PoolRepository < ActiveRecord::Base ...@@ -85,7 +85,11 @@ class PoolRepository < ActiveRecord::Base
def unlink_repository(repository) def unlink_repository(repository)
object_pool.unlink_repository(repository.raw) object_pool.unlink_repository(repository.raw)
mark_obsolete unless member_projects.where.not(id: repository.project.id).exists? if member_projects.where.not(id: repository.project.id).exists?
true
else
mark_obsolete
end
end end
def object_pool def object_pool
......
...@@ -2040,7 +2040,7 @@ class Project < ActiveRecord::Base ...@@ -2040,7 +2040,7 @@ class Project < ActiveRecord::Base
end end
def leave_pool_repository def leave_pool_repository
pool_repository&.unlink_repository(repository) pool_repository&.unlink_repository(repository) && update_column(:pool_repository_id, nil)
end end
private private
......
...@@ -4387,6 +4387,17 @@ describe Project do ...@@ -4387,6 +4387,17 @@ describe Project do
end end
end end
describe '#leave_pool_repository' do
let(:pool) { create(:pool_repository) }
let(:project) { create(:project, :repository, pool_repository: pool) }
it 'removes the membership' do
project.leave_pool_repository
expect(pool.member_projects.reload).not_to include(project)
end
end
def rugged_config def rugged_config
rugged_repo(project.repository).config rugged_repo(project.repository).config
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment