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.
This commit is contained in:
Zeger-Jan van de Weg 2019-01-08 11:54:18 +01:00
parent a996e4e3b3
commit e672ed8494
No known key found for this signature in database
GPG Key ID: 65F6A8D64A88ABAC
3 changed files with 17 additions and 2 deletions

View File

@ -85,7 +85,11 @@ class PoolRepository < ActiveRecord::Base
def unlink_repository(repository)
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
def object_pool

View File

@ -2040,7 +2040,7 @@ class Project < ActiveRecord::Base
end
def leave_pool_repository
pool_repository&.unlink_repository(repository)
pool_repository&.unlink_repository(repository) && update_column(:pool_repository_id, nil)
end
private

View File

@ -4387,6 +4387,17 @@ describe Project do
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
rugged_repo(project.repository).config
end