Welcome to mirror list, hosted at ThFree Co, Russian Federation.

play_spec.rb « build « status « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: abefdbe7c66caf7c1607e7bab3ce97327ad6c986 (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
require 'spec_helper'

describe Gitlab::Ci::Status::Build::Play do
  let(:user) { create(:user) }
  let(:build) { create(:ci_build, :manual) }
  let(:status) { Gitlab::Ci::Status::Core.new(build, user) }

  subject { described_class.new(status) }

  context 'when user is allowed to update build' do
    context 'when user can push to branch' do
      before { build.project.add_master(user) }

      describe '#has_action?' do
        it { is_expected.to have_action }
      end

      describe '#label' do
        it 'has a label that says it is a manual action' do
          expect(subject.label).to eq 'manual play action'
        end
      end
    end

    context 'when user can not push to the branch' do
      before { build.project.add_developer(user) }

      describe 'has_action?' do
        it { is_expected.not_to have_action }
      end

      describe '#label' do
        it 'has a label that says user is not allowed to play it' do
          expect(subject.label).to eq 'manual play action (not allowed)'
        end
      end
    end
  end

  context 'when user is not allowed to update build' do
    describe '#has_action?' do
      it { is_expected.not_to have_action }
    end
  end

  describe '#action_path' do
    it { expect(subject.action_path).to include "#{build.id}/play" }
  end

  describe '#action_icon' do
    it { expect(subject.action_icon).to eq 'icon_action_play' }
  end

  describe '#action_title' do
    it { expect(subject.action_title).to eq 'Play' }
  end

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

    context 'when build is playable' do
      context 'when build stops an environment' do
        let(:build) do
          create(:ci_build, :playable, :teardown_environment)
        end

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

      context 'when build does not stop an environment' do
        let(:build) { create(:ci_build, :playable) }

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

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

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