summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/status/build/action_spec.rb
blob: bdec582b57bbe304be2325a7f1f8bd6cc118f16b (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
require 'spec_helper'

describe Gitlab::Ci::Status::Build::Action do
  let(:status) { double('core status') }
  let(:user) { double('user') }

  subject do
    described_class.new(status)
  end

  describe '#label' do
    before do
      allow(status).to receive(:label).and_return('label')
    end

    context 'when status has action' do
      before do
        allow(status).to receive(:has_action?).and_return(true)
      end

      it 'does not append text' do
        expect(subject.label).to eq 'label'
      end
    end

    context 'when status does not have action' do
      before do
        allow(status).to receive(:has_action?).and_return(false)
      end

      it 'appends text about action not allowed' do
        expect(subject.label).to eq 'label (not allowed)'
      end
    end
  end

  describe '.matches?' do
    subject { described_class.matches?(build, user) }

    context 'when build is playable action' do
      let(:build) { create(:ci_build, :playable) }

      it 'is a correct match' do
        expect(subject).to be true
      end
    end

    context 'when build is not playable action' do
      let(:build) { create(:ci_build, :non_playable) }

      it 'does not match' do
        expect(subject).to be false
      end
    end
  end

  describe '#badge_tooltip' do
    let(:user) { create(:user) }
    let(:build) { create(:ci_build, :non_playable) }
    let(:status) { Gitlab::Ci::Status::Core.new(build, user) }

    it 'returns the status' do
      expect(subject.badge_tooltip).to eq('created')
    end
  end
end