summaryrefslogtreecommitdiff
path: root/spec/models/external_issue_spec.rb
blob: 47b13ff50cfc5f8109cb369068f4b720e31a3b10 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ExternalIssue do
  let(:project) { double('project', id: 1, to_reference: 'namespace1/project1') }
  let(:issue)   { described_class.new('EXT-1234', project) }

  describe 'modules' do
    subject { described_class }

    it { is_expected.to include_module(Referable) }
  end

  describe '#to_reference' do
    it 'returns a String reference to the object' do
      expect(issue.to_reference).to eq issue.id
    end
  end

  describe '#title' do
    it 'returns a title' do
      expect(issue.title).to eq "External Issue #{issue}"
    end
  end

  describe '#reference_link_text' do
    context 'if issue id has a prefix' do
      it 'returns the issue ID' do
        expect(issue.reference_link_text).to eq 'EXT-1234'
      end
    end

    context 'if issue id is a number' do
      let(:issue) { described_class.new('1234', project) }

      it 'returns the issue ID prefixed by #' do
        expect(issue.reference_link_text).to eq '#1234'
      end
    end
  end

  describe '#project_id' do
    it 'returns the ID of the project' do
      expect(issue.project_id).to eq(project.id)
    end
  end

  describe '#hash' do
    it 'returns the hash of its [class, to_s] pair' do
      issue_2 = described_class.new(issue.to_s, project)

      expect(issue.hash).to eq(issue_2.hash)
    end
  end
end