2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-12-07 16:56:59 -05:00
|
|
|
describe MergeRequestWidgetEntity do
|
2018-08-31 13:16:34 -04:00
|
|
|
include ProjectForksHelper
|
|
|
|
|
2017-10-10 10:56:04 -04:00
|
|
|
let(:project) { create :project, :repository }
|
2017-05-09 00:15:34 -04:00
|
|
|
let(:resource) { create(:merge_request, source_project: project, target_project: project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2017-12-01 08:26:51 -05:00
|
|
|
let(:request) { double('request', current_user: user, project: project) }
|
2017-05-09 00:15:34 -04:00
|
|
|
|
|
|
|
subject do
|
|
|
|
described_class.new(resource, request: request).as_json
|
|
|
|
end
|
|
|
|
|
2018-07-10 05:35:16 -04:00
|
|
|
describe 'source_project_full_path' do
|
|
|
|
it 'includes the full path of the source project' do
|
|
|
|
expect(subject[:source_project_full_path]).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the source project is missing' do
|
|
|
|
it 'returns `nil` for the source project' do
|
|
|
|
resource.allow_broken = true
|
|
|
|
resource.update!(source_project: nil)
|
|
|
|
|
|
|
|
expect(subject[:source_project_full_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-20 18:18:51 -04:00
|
|
|
describe 'issues links' do
|
|
|
|
it 'includes issues links when requested' do
|
|
|
|
data = described_class.new(resource, request: request, issues_links: true).as_json
|
|
|
|
|
|
|
|
expect(data).to include(:issues_links)
|
|
|
|
expect(data[:issues_links]).to include(:assign_to_closing, :closing, :mentioned_but_not_closing)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'omits issue links by default' do
|
|
|
|
expect(subject).not_to include(:issues_links)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
it 'has email_patches_path' do
|
|
|
|
expect(subject[:email_patches_path])
|
2019-12-18 16:07:37 -05:00
|
|
|
.to eq("/#{resource.project.full_path}/merge_requests/#{resource.iid}.patch")
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has plain_diff_path' do
|
|
|
|
expect(subject[:plain_diff_path])
|
2019-12-18 16:07:37 -05:00
|
|
|
.to eq("/#{resource.project.full_path}/merge_requests/#{resource.iid}.diff")
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
|
2017-12-20 04:01:21 -05:00
|
|
|
describe 'when source project is deleted' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
2018-08-31 13:16:34 -04:00
|
|
|
let(:forked_project) { fork_project(project) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project) }
|
2017-12-20 04:01:21 -05:00
|
|
|
|
|
|
|
it 'returns a blank rebase_path' do
|
|
|
|
allow(merge_request).to receive(:should_be_rebased?).and_return(true)
|
2018-08-31 13:16:34 -04:00
|
|
|
forked_project.destroy
|
2017-12-20 04:01:21 -05:00
|
|
|
merge_request.reload
|
|
|
|
|
|
|
|
entity = described_class.new(merge_request, request: request).as_json
|
|
|
|
|
|
|
|
expect(entity[:rebase_path]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|