summaryrefslogtreecommitdiff
path: root/spec/presenters/release_presenter_spec.rb
blob: 8bca38f70543ef95d6bcb326733d73c2c15fc576 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# frozen_string_literal: true

require 'spec_helper'

describe ReleasePresenter do
  include Gitlab::Routing.url_helpers

  let_it_be(:project) { create(:project, :repository) }
  let(:developer) { create(:user) }
  let(:guest) { create(:user) }
  let(:user) { developer }
  let(:release) { create(:release, project: project) }
  let(:presenter) { described_class.new(release, current_user: user) }

  before do
    project.add_developer(developer)
    project.add_guest(guest)
  end

  describe '#commit_path' do
    subject { presenter.commit_path }

    it 'returns commit path' do
      is_expected.to eq(project_commit_path(project, release.commit.id))
    end

    context 'when commit is not found' do
      let(:release) { create(:release, project: project, sha: 'not-found') }

      it { is_expected.to be_nil }
    end

    context 'when user is guest' do
      let(:user) { guest }

      it { is_expected.to be_nil }
    end
  end

  describe '#tag_path' do
    subject { presenter.tag_path }

    it 'returns tag path' do
      is_expected.to eq(project_tag_path(project, release.tag))
    end

    context 'when user is guest' do
      let(:user) { guest }

      it { is_expected.to be_nil }
    end
  end

  describe '#merge_requests_url' do
    subject { presenter.merge_requests_url }

    it 'returns merge requests url' do
      is_expected.to match /#{project_merge_requests_url(project)}/
    end

    context 'when release_mr_issue_urls feature flag is disabled' do
      before do
        stub_feature_flags(release_mr_issue_urls: false)
      end

      it { is_expected.to be_nil }
    end
  end

  describe '#issues_url' do
    subject { presenter.issues_url }

    it 'returns merge requests url' do
      is_expected.to match /#{project_issues_url(project)}/
    end

    context 'when release_mr_issue_urls feature flag is disabled' do
      before do
        stub_feature_flags(release_mr_issue_urls: false)
      end

      it { is_expected.to be_nil }
    end
  end
end