2016-03-22 10:34:35 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Projects::UnlinkForkService do
|
2017-09-30 14:21:08 -04:00
|
|
|
include ProjectForksHelper
|
2016-03-22 10:34:35 -04:00
|
|
|
|
2017-09-30 14:21:08 -04:00
|
|
|
subject { described_class.new(forked_project, user) }
|
|
|
|
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:forked_project) { fork_project(project, user) }
|
2016-03-22 10:34:35 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
context 'with opened merge request on the source project' do
|
2018-08-31 13:16:34 -04:00
|
|
|
let(:merge_request) { create(:merge_request, source_project: forked_project, target_project: forked_project.forked_from_project) }
|
2017-11-03 06:31:29 -04:00
|
|
|
let(:merge_request2) { create(:merge_request, source_project: forked_project, target_project: fork_project(project)) }
|
|
|
|
let(:merge_request_in_fork) { create(:merge_request, source_project: forked_project, target_project: forked_project) }
|
|
|
|
|
2017-09-30 14:21:08 -04:00
|
|
|
let(:mr_close_service) { MergeRequests::CloseService.new(forked_project, user) }
|
2016-03-22 10:34:35 -04:00
|
|
|
|
|
|
|
before do
|
2017-06-21 09:48:12 -04:00
|
|
|
allow(MergeRequests::CloseService).to receive(:new)
|
2017-09-30 14:21:08 -04:00
|
|
|
.with(forked_project, user)
|
2017-06-21 09:48:12 -04:00
|
|
|
.and_return(mr_close_service)
|
2016-03-22 10:34:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'close all pending merge requests' do
|
|
|
|
expect(mr_close_service).to receive(:execute).with(merge_request)
|
2017-11-03 06:31:29 -04:00
|
|
|
expect(mr_close_service).to receive(:execute).with(merge_request2)
|
2016-03-22 10:34:35 -04:00
|
|
|
|
|
|
|
subject.execute
|
|
|
|
end
|
2017-11-03 06:31:29 -04:00
|
|
|
|
|
|
|
it 'does not close merge requests for the project being unlinked' do
|
|
|
|
expect(mr_close_service).not_to receive(:execute).with(merge_request_in_fork)
|
|
|
|
end
|
2016-03-22 10:34:35 -04:00
|
|
|
end
|
|
|
|
|
2017-09-30 14:21:08 -04:00
|
|
|
it 'removes the link to the fork network' do
|
|
|
|
expect(forked_project.fork_network_member).to be_present
|
|
|
|
expect(forked_project.fork_network).to be_present
|
2016-03-22 10:34:35 -04:00
|
|
|
|
2016-04-03 11:17:14 -04:00
|
|
|
subject.execute
|
2017-09-30 14:21:08 -04:00
|
|
|
forked_project.reload
|
|
|
|
|
|
|
|
expect(forked_project.fork_network_member).to be_nil
|
|
|
|
expect(forked_project.reload.fork_network).to be_nil
|
2016-03-22 10:34:35 -04:00
|
|
|
end
|
2017-08-14 09:22:09 -04:00
|
|
|
|
|
|
|
it 'refreshes the forks count cache of the source project' do
|
2017-09-30 14:21:08 -04:00
|
|
|
source = forked_project.forked_from_project
|
2017-08-14 09:22:09 -04:00
|
|
|
|
|
|
|
expect(source.forks_count).to eq(1)
|
|
|
|
|
|
|
|
subject.execute
|
|
|
|
|
|
|
|
expect(source.forks_count).to be_zero
|
|
|
|
end
|
2017-11-03 06:31:29 -04:00
|
|
|
|
2017-12-19 04:57:12 -05:00
|
|
|
context 'when the source has LFS objects' do
|
|
|
|
let(:lfs_object) { create(:lfs_object) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
lfs_object.projects << project
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'links the fork to the lfs object before unlinking' do
|
|
|
|
subject.execute
|
|
|
|
|
|
|
|
expect(lfs_object.projects).to include(forked_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not fail if the lfs objects were already linked' do
|
|
|
|
lfs_object.projects << forked_project
|
|
|
|
|
|
|
|
expect { subject.execute }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-03 06:31:29 -04:00
|
|
|
context 'when the original project was deleted' do
|
|
|
|
it 'does not fail when the original project is deleted' do
|
|
|
|
source = forked_project.forked_from_project
|
|
|
|
source.destroy
|
|
|
|
forked_project.reload
|
|
|
|
|
|
|
|
expect { subject.execute }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
2016-03-22 10:34:35 -04:00
|
|
|
end
|