Commit 6e8902d6 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix-pending-delete-forks' into 'master'

Don't resolve fork relationships for projects pending delete

See merge request !12603
parents 71a6c83a cb1f3423
class ForkedProjectLink < ActiveRecord::Base class ForkedProjectLink < ActiveRecord::Base
belongs_to :forked_to_project, class_name: 'Project' belongs_to :forked_to_project, -> { where.not(pending_delete: true) }, class_name: 'Project'
belongs_to :forked_from_project, class_name: 'Project' belongs_to :forked_from_project, -> { where.not(pending_delete: true) }, class_name: 'Project'
end end
...@@ -2,53 +2,75 @@ require 'spec_helper' ...@@ -2,53 +2,75 @@ require 'spec_helper'
describe ForkedProjectLink, "add link on fork" do describe ForkedProjectLink, "add link on fork" do
let(:project_from) { create(:project, :repository) } let(:project_from) { create(:project, :repository) }
let(:project_to) { fork_project(project_from, user) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:namespace) { user.namespace } let(:namespace) { user.namespace }
before do before do
create(:project_member, :reporter, user: user, project: project_from) project_from.add_reporter(user)
@project_to = fork_project(project_from, user) end
it 'project_from knows its forks' do
_ = project_to
expect(project_from.forks.count).to eq(1)
end end
it "project_to knows it is forked" do it "project_to knows it is forked" do
expect(@project_to.forked?).to be_truthy expect(project_to.forked?).to be_truthy
end end
it "project knows who it is forked from" do it "project knows who it is forked from" do
expect(@project_to.forked_from_project).to eq(project_from) expect(project_to.forked_from_project).to eq(project_from)
end end
end
describe '#forked?' do context 'project_to is pending_delete' do
let(:forked_project_link) { build(:forked_project_link) } before do
let(:project_from) { create(:project, :repository) } project_to.update!(pending_delete: true)
let(:project_to) { create(:project, forked_project_link: forked_project_link) } end
before :each do it { expect(project_from.forks.count).to eq(0) }
forked_project_link.forked_from_project = project_from
forked_project_link.forked_to_project = project_to
forked_project_link.save!
end end
it "project_to knows it is forked" do context 'project_from is pending_delete' do
expect(project_to.forked?).to be_truthy before do
end project_from.update!(pending_delete: true)
end
it "project_from is not forked" do it { expect(project_to.forked_from_project).to be_nil }
expect(project_from.forked?).to be_falsey
end end
it "project_to.destroy destroys fork_link" do describe '#forked?' do
expect(forked_project_link).to receive(:destroy) let(:project_to) { create(:project, forked_project_link: forked_project_link) }
project_to.destroy let(:forked_project_link) { build(:forked_project_link) }
before do
forked_project_link.forked_from_project = project_from
forked_project_link.forked_to_project = project_to
forked_project_link.save!
end
it "project_to knows it is forked" do
expect(project_to.forked?).to be_truthy
end
it "project_from is not forked" do
expect(project_from.forked?).to be_falsey
end
it "project_to.destroy destroys fork_link" do
expect(forked_project_link).to receive(:destroy)
project_to.destroy
end
end end
end
def fork_project(from_project, user) def fork_project(from_project, user)
shell = double('gitlab_shell', fork_repository: true) service = Projects::ForkService.new(from_project, user)
shell = double('gitlab_shell', fork_repository: true)
service = Projects::ForkService.new(from_project, user) allow(service).to receive(:gitlab_shell).and_return(shell)
allow(service).to receive(:gitlab_shell).and_return(shell)
service.execute service.execute
end
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