2019-03-28 10:33:06 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-01 03:50:53 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 09:08:32 +00:00
|
|
|
RSpec.describe MergeRequestsHelper do
|
2017-12-01 19:08:30 +00:00
|
|
|
include ActionView::Helpers::UrlHelper
|
2017-09-29 08:04:50 +00:00
|
|
|
include ProjectForksHelper
|
2017-12-01 19:08:30 +00:00
|
|
|
|
2015-12-22 02:57:51 +00:00
|
|
|
describe 'ci_build_details_path' do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2015-12-22 02:57:51 +00:00
|
|
|
let(:merge_request) { MergeRequest.new }
|
|
|
|
let(:ci_service) { CiService.new }
|
2016-06-02 14:19:18 +00:00
|
|
|
let(:last_commit) { Ci::Pipeline.new({}) }
|
2015-12-22 02:57:51 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
allow(merge_request).to receive(:source_project).and_return(project)
|
|
|
|
allow(merge_request).to receive(:last_commit).and_return(last_commit)
|
|
|
|
allow(project).to receive(:ci_service).and_return(ci_service)
|
|
|
|
allow(last_commit).to receive(:sha).and_return('12d65c')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include api credentials in a link' do
|
2017-06-21 13:48:12 +00:00
|
|
|
allow(ci_service)
|
|
|
|
.to receive(:build_page).and_return("http://secretuser:secretpass@jenkins.example.com:8888/job/test1/scm/bySHA1/12d65c")
|
2016-05-23 23:37:59 +00:00
|
|
|
expect(helper.ci_build_details_path(merge_request)).not_to match("secret")
|
2015-12-22 02:57:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-22 21:06:19 +00:00
|
|
|
describe '#state_name_with_icon' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
let(:merge_request) { MergeRequest.new }
|
|
|
|
|
|
|
|
where(:state, :expected_name, :expected_icon) do
|
|
|
|
:merged? | 'Merged' | 'git-merge'
|
|
|
|
:closed? | 'Closed' | 'close'
|
|
|
|
:opened? | 'Open' | 'issue-open-m'
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
before do
|
|
|
|
allow(merge_request).to receive(state).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns name and icon' do
|
|
|
|
name, icon = helper.state_name_with_icon(merge_request)
|
|
|
|
|
|
|
|
expect(name).to eq(expected_name)
|
|
|
|
expect(icon).to eq(expected_icon)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-17 22:08:14 +00:00
|
|
|
describe '#format_mr_branch_names' do
|
|
|
|
describe 'within the same project' do
|
2015-10-01 03:50:53 +00:00
|
|
|
let(:merge_request) { create(:merge_request) }
|
2019-12-17 18:07:48 +00:00
|
|
|
|
2015-10-01 03:50:53 +00:00
|
|
|
subject { format_mr_branch_names(merge_request) }
|
|
|
|
|
|
|
|
it { is_expected.to eq([merge_request.source_branch, merge_request.target_branch]) }
|
|
|
|
end
|
|
|
|
|
2015-12-17 22:08:14 +00:00
|
|
|
describe 'within different projects' do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2017-09-29 08:04:50 +00:00
|
|
|
let(:forked_project) { fork_project(project) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project) }
|
2015-10-01 03:50:53 +00:00
|
|
|
subject { format_mr_branch_names(merge_request) }
|
2019-10-18 11:11:44 +00:00
|
|
|
|
2017-09-29 08:04:50 +00:00
|
|
|
let(:source_title) { "#{forked_project.full_path}:#{merge_request.source_branch}" }
|
2017-07-20 09:34:09 +00:00
|
|
|
let(:target_title) { "#{project.full_path}:#{merge_request.target_branch}" }
|
2015-10-01 03:50:53 +00:00
|
|
|
|
|
|
|
it { is_expected.to eq([source_title, target_title]) }
|
|
|
|
end
|
|
|
|
end
|
2017-12-01 19:08:30 +00:00
|
|
|
|
|
|
|
describe '#tab_link_for' do
|
|
|
|
let(:merge_request) { create(:merge_request, :simple) }
|
2020-09-02 15:10:54 +00:00
|
|
|
let(:options) { {} }
|
2017-12-01 19:08:30 +00:00
|
|
|
|
|
|
|
subject { tab_link_for(merge_request, :show, options) { 'Discussion' } }
|
|
|
|
|
|
|
|
describe 'supports the :force_link option' do
|
|
|
|
let(:options) { { force_link: true } }
|
|
|
|
|
|
|
|
it 'removes the data-toggle attributes' do
|
2018-06-30 13:17:46 +00:00
|
|
|
is_expected.not_to match(/data-toggle="tabvue"/)
|
2017-12-01 19:08:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-10-01 03:50:53 +00:00
|
|
|
end
|