BigW Consortium Gitlab

merge_requests_helper_spec.rb 1.71 KB
Newer Older
1 2 3
require 'spec_helper'

describe MergeRequestsHelper do
4
  include ProjectForksHelper
5
  describe 'ci_build_details_path' do
6
    let(:project) { create(:project) }
7 8
    let(:merge_request) { MergeRequest.new }
    let(:ci_service) { CiService.new }
9
    let(:last_commit) { Ci::Pipeline.new({}) }
10 11 12 13 14 15 16 17 18

    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
19 20
      allow(ci_service)
        .to receive(:build_page).and_return("http://secretuser:secretpass@jenkins.example.com:8888/job/test1/scm/bySHA1/12d65c")
21
      expect(helper.ci_build_details_path(merge_request)).not_to match("secret")
22 23 24
    end
  end

Drew Blessing committed
25 26
  describe '#format_mr_branch_names' do
    describe 'within the same project' do
27 28 29 30 31 32
      let(:merge_request) { create(:merge_request) }
      subject { format_mr_branch_names(merge_request) }

      it { is_expected.to eq([merge_request.source_branch, merge_request.target_branch]) }
    end

Drew Blessing committed
33
    describe 'within different projects' do
34
      let(:project) { create(:project) }
35 36
      let(:forked_project) { fork_project(project) }
      let(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project) }
37
      subject { format_mr_branch_names(merge_request) }
38
      let(:source_title) { "#{forked_project.full_path}:#{merge_request.source_branch}" }
39
      let(:target_title) { "#{project.full_path}:#{merge_request.target_branch}" }
40 41 42 43 44

      it { is_expected.to eq([source_title, target_title]) }
    end
  end
end