summaryrefslogtreecommitdiff
path: root/spec/presenters/issue_presenter_spec.rb
blob: df43b0279dd1d9b397ce38193f08b60ddfe2527b (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe IssuePresenter do
  include Gitlab::Routing.url_helpers

  let_it_be(:user) { create(:user) }
  let_it_be(:group) { create(:group) }
  let_it_be(:project) { create(:project, group: group) }
  let_it_be(:issue) { create(:issue, project: project) }
  let_it_be(:task) { create(:issue, :task, project: project) }

  let(:presented_issue) { issue }
  let(:presenter) { described_class.new(presented_issue, current_user: user) }

  before_all do
    group.add_developer(user)
  end

  describe '#web_url' do
    it 'returns correct path' do
      expect(presenter.web_url).to eq("http://localhost/#{group.name}/#{project.name}/-/issues/#{presented_issue.iid}")
    end

    context 'when issue type is task' do
      let(:presented_issue) { task }

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

        it 'returns a work item url for the task' do
          expect(presenter.web_url).to eq(project_work_items_url(project, work_items_path: presented_issue.id))
        end
      end

      it 'returns a work item url using iid for the task' do
        expect(presenter.web_url).to eq(
          project_work_items_url(project, work_items_path: presented_issue.iid, iid_path: true)
        )
      end
    end
  end

  describe '#subscribed?' do
    subject { presenter.subscribed? }

    it 'returns not subscribed' do
      is_expected.to be(false)
    end

    it 'returns subscribed' do
      create(:subscription, user: user, project: project, subscribable: presented_issue, subscribed: true)

      is_expected.to be(true)
    end
  end

  describe '#issue_path' do
    it 'returns correct path' do
      expect(presenter.issue_path).to eq("/#{group.name}/#{project.name}/-/issues/#{presented_issue.iid}")
    end

    context 'when issue type is task' do
      let(:presented_issue) { task }

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

        it 'returns a work item path for the task' do
          expect(presenter.issue_path).to eq(project_work_items_path(project, work_items_path: presented_issue.id))
        end
      end

      it 'returns a work item path using iid for the task' do
        expect(presenter.issue_path).to eq(
          project_work_items_path(project, work_items_path: presented_issue.iid, iid_path: true)
        )
      end
    end
  end

  describe '#project_emails_disabled?' do
    subject { presenter.project_emails_disabled? }

    it 'returns false when emails notifications is enabled for project' do
      is_expected.to be(false)
    end

    context 'when emails notifications is disabled for project' do
      before do
        allow(project).to receive(:emails_disabled?).and_return(true)
      end

      it { is_expected.to be(true) }
    end
  end
end