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

describe Gitlab::Ci::Status::Build::Play do
4
  let(:status) { double('core') }
5 6
  let(:user) { double('user') }

7
  subject { described_class.new(status) }
8 9

  describe '#text' do
10
    it { expect(subject.text).to eq 'manual' }
11 12 13
  end

  describe '#label' do
14
    it { expect(subject.label).to eq 'manual play action' }
15 16 17
  end

  describe '#icon' do
18
    it { expect(subject.icon).to eq 'icon_status_manual' }
19 20
  end

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
  describe 'action details' do
    let(:user) { create(:user) }
    let(:build) { create(:ci_build) }
    let(:status) { Gitlab::Ci::Status::Core.new(build, user) }

    describe '#has_action?' do
      context 'when user is allowed to update build' do
        before { build.project.team << [user, :developer] }

        it { is_expected.to have_action }
      end

      context 'when user is not allowed to update build' 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 'play' }
    end

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

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

54
    context 'when build is playable' do
55 56 57 58 59 60
      context 'when build stops an environment' do
        let(:build) do
          create(:ci_build, :playable, :teardown_environment)
        end

        it 'does not match' do
61
          expect(subject).to be false
62 63 64 65 66 67 68
        end
      end

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

        it 'is a correct match' do
69
          expect(subject).to be true
70 71 72 73 74 75 76 77
        end
      end
    end

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

      it 'does not match' do
78
        expect(subject).to be false
79 80 81 82
      end
    end
  end
end