play_spec.rb 2.46 KB
Newer Older
1 2 3
require 'spec_helper'

describe Gitlab::Ci::Status::Build::Play do
4
  let(:user) { create(:user) }
5
  let(:project) { build.project }
6 7
  let(:build) { create(:ci_build, :manual) }
  let(:status) { Gitlab::Ci::Status::Core.new(build, user) }
8

9
  subject { described_class.new(status) }
10

11 12 13 14 15 16
  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

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  describe '#status_tooltip' do
    it 'does not override status status_tooltip' do
      expect(status).to receive(:status_tooltip)

      subject.status_tooltip
    end
  end

  describe '#badge_tooltip' do
    it 'does not override status badge_tooltip' do
      expect(status).to receive(:badge_tooltip)

      subject.badge_tooltip
    end
  end

33 34
  describe '#has_action?' do
    context 'when user is allowed to update build' do
35 36 37 38 39 40 41
      context 'when user is allowed to trigger protected action' do
        before do
          project.add_developer(user)

          create(:protected_branch, :developers_can_merge,
                 name: build.ref, project: project)
        end
42

43 44
        it { is_expected.to have_action }
      end
45

46
      context 'when user can not push to the branch' do
47 48 49
        before do
          build.project.add_developer(user)
        end
50

51
        it { is_expected.not_to have_action }
52 53 54
      end
    end

55
    context 'when user is not allowed to update build' do
56
      it { is_expected.not_to have_action }
57
    end
58
  end
59

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

64
  describe '#action_icon' do
Tim Zallmann's avatar
Tim Zallmann committed
65
    it { expect(subject.action_icon).to eq 'play' }
66 67 68 69
  end

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

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

75
    context 'when build is playable' do
76 77 78 79 80 81
      context 'when build stops an environment' do
        let(:build) do
          create(:ci_build, :playable, :teardown_environment)
        end

        it 'does not match' do
82
          expect(subject).to be false
83 84 85 86 87 88 89
        end
      end

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

        it 'is a correct match' do
90
          expect(subject).to be true
91 92 93 94 95 96 97 98
        end
      end
    end

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

      it 'does not match' do
99
        expect(subject).to be false
100 101 102 103
      end
    end
  end
end