summaryrefslogtreecommitdiff
path: root/spec/presenters/commit_presenter_spec.rb
blob: bc749acfa3ac739cb81f38e6114da785a06591a5 (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
# frozen_string_literal: true

require 'spec_helper'

describe CommitPresenter do
  let(:project) { create(:project, :repository) }
  let(:commit) { project.commit }
  let(:user) { create(:user) }
  let(:presenter) { described_class.new(commit, current_user: user) }

  describe '#status_for' do
    subject { presenter.status_for('ref') }

    context 'when user can read_commit_status' do
      before do
        allow(presenter).to receive(:can?).with(user, :read_commit_status, project).and_return(true)
      end

      it 'returns commit status for ref' do
        pipeline = double
        status = double

        expect(commit).to receive(:latest_pipeline).with('ref').and_return(pipeline)
        expect(pipeline).to receive(:detailed_status).with(user).and_return(status)

        expect(subject).to eq(status)
      end
    end

    context 'when user can not read_commit_status' do
      it 'is nil' do
        is_expected.to eq(nil)
      end
    end
  end

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

    context 'when user can read pipeline' do
      before do
        allow(presenter).to receive(:can?).with(user, :read_pipeline, project).and_return(true)
      end

      it 'returns if there are any pipelines for commit' do
        expect(commit).to receive_message_chain(:pipelines, :any?).and_return(true)

        expect(subject).to eq(true)
      end
    end

    context 'when user can not read pipeline' do
      it 'is false' do
        is_expected.to eq(false)
      end
    end
  end

  describe '#signature_html' do
    let(:signature) { 'signature' }

    before do
      expect(commit).to receive(:has_signature?).and_return(true)
      allow(ApplicationController.renderer).to receive(:render).and_return(signature)
    end

    it 'renders html for displaying signature' do
      expect(presenter.signature_html).to eq(signature)
    end
  end
end