From cb1f3423876f84861facc4c3631eeb4b453ceee6 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Mon, 3 Jul 2017 11:31:37 +0100 Subject: [PATCH] Don't resolve fork relationships for projects pending delete --- app/models/forked_project_link.rb | 4 ++-- spec/models/forked_project_link_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/models/forked_project_link.rb b/app/models/forked_project_link.rb index 36cf7ad6a28..8d35864eff6 100644 --- a/app/models/forked_project_link.rb +++ b/app/models/forked_project_link.rb @@ -1,4 +1,4 @@ class ForkedProjectLink < ActiveRecord::Base - belongs_to :forked_to_project, class_name: 'Project' - belongs_to :forked_from_project, class_name: 'Project' + belongs_to :forked_to_project, -> { where.not(pending_delete: true) }, class_name: 'Project' + belongs_to :forked_from_project, -> { where.not(pending_delete: true) }, class_name: 'Project' end diff --git a/spec/models/forked_project_link_spec.rb b/spec/models/forked_project_link_spec.rb index 4fd250bd4c6..5c13cf584f9 100644 --- a/spec/models/forked_project_link_spec.rb +++ b/spec/models/forked_project_link_spec.rb @@ -24,6 +24,22 @@ describe ForkedProjectLink, "add link on fork" do expect(project_to.forked_from_project).to eq(project_from) end + context 'project_to is pending_delete' do + before do + project_to.update!(pending_delete: true) + end + + it { expect(project_from.forks.count).to eq(0) } + end + + context 'project_from is pending_delete' do + before do + project_from.update!(pending_delete: true) + end + + it { expect(project_to.forked_from_project).to be_nil } + end + describe '#forked?' do let(:project_to) { create(:project, forked_project_link: forked_project_link) } let(:forked_project_link) { build(:forked_project_link) }