2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::ImportExport::MergeRequestParser do
|
2018-03-17 18:26:18 +05:30
|
|
|
include ProjectForksHelper
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let!(:project) { create(:project, :repository, name: 'test-repo-restorer', path: 'test-repo-restorer') }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:forked_project) { fork_project(project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
let!(:merge_request) do
|
2018-03-17 18:26:18 +05:30
|
|
|
create(:merge_request, source_project: forked_project, target_project: project)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
let(:parsed_merge_request) do
|
|
|
|
described_class.new(project,
|
2018-03-17 18:26:18 +05:30
|
|
|
'abcd',
|
2017-08-17 22:00:37 +05:30
|
|
|
merge_request,
|
|
|
|
merge_request.as_json).parse!
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2018-11-08 19:23:39 +05:30
|
|
|
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
|
|
|
|
FileUtils.rm_rf(project.repository.path_to_repo)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a source branch' do
|
|
|
|
expect(project.repository.branch_exists?(parsed_merge_request.source_branch)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a target branch' do
|
|
|
|
expect(project.repository.branch_exists?(parsed_merge_request.target_branch)).to be true
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'parses a MR that has no source branch' do
|
2020-01-01 13:55:28 +05:30
|
|
|
allow_next_instance_of(described_class) do |instance|
|
|
|
|
allow(instance).to receive(:branch_exists?).and_call_original
|
|
|
|
allow(instance).to receive(:branch_exists?).with(merge_request.source_branch).and_return(false)
|
|
|
|
allow(instance).to receive(:fork_merge_request?).and_return(true)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expect(parsed_merge_request).to eq(merge_request)
|
|
|
|
end
|
2019-03-13 22:55:13 +05:30
|
|
|
|
|
|
|
context 'when the merge request has diffs' do
|
|
|
|
let(:merge_request) do
|
|
|
|
build(:merge_request, source_project: forked_project, target_project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the diff is invalid' do
|
|
|
|
let(:merge_request_diff) { build(:merge_request_diff, merge_request: merge_request, base_commit_sha: 'foobar') }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
it 'sets the diff to empty diff' do
|
2019-03-13 22:55:13 +05:30
|
|
|
expect(merge_request_diff).to be_invalid
|
|
|
|
expect(merge_request_diff.merge_request).to eq merge_request
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(parsed_merge_request.merge_request_diff).to be_empty
|
2019-03-13 22:55:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|