BigW Consortium Gitlab

statuseable_spec.rb 3.41 KB
Newer Older
1 2
require 'spec_helper'

3
describe Statuseable do
4 5
  before do
    @object = Object.new
6
    @object.extend(Statuseable::ClassMethods)
7 8 9 10
  end

  describe '.status' do
    before do
11
      allow(@object).to receive(:all).and_return(CommitStatus.where(id: statuses))
12 13 14
    end

    subject { @object.status }
15
    
16 17 18 19 20
    shared_examples 'build status summary' do
      context 'all successful' do
        let(:statuses) { Array.new(2) { create(type, status: :success) } }
        it { is_expected.to eq 'success' }
      end
21

22 23 24
      context 'at least one failed' do
        let(:statuses) do
          [create(type, status: :success), create(type, status: :failed)]
25
        end
26

27 28 29 30 31 32
        it { is_expected.to eq 'failed' }
      end

      context 'at least one running' do
        let(:statuses) do
          [create(type, status: :success), create(type, status: :running)]
33
        end
34

35 36 37 38 39 40
        it { is_expected.to eq 'running' }
      end

      context 'at least one pending' do
        let(:statuses) do
          [create(type, status: :success), create(type, status: :pending)]
41
        end
42

43 44 45 46 47 48 49
        it { is_expected.to eq 'running' }
      end

      context 'success and failed but allowed to fail' do
        let(:statuses) do
          [create(type, status: :success),
           create(type, status: :failed, allow_failure: true)]
50
        end
51

52 53 54 55 56 57 58 59
        it { is_expected.to eq 'success' }
      end

      context 'one failed but allowed to fail' do
        let(:statuses) { [create(type, status: :failed, allow_failure: true)] }
        it { is_expected.to eq 'success' }
      end

60 61 62 63
      context 'success and canceled' do
        let(:statuses) do
          [create(type, status: :success), create(type, status: :canceled)]
        end
64 65 66 67 68 69 70 71 72

        it { is_expected.to eq 'canceled' }
      end

      context 'one failed and one canceled' do
        let(:statuses) do
          [create(type, status: :failed), create(type, status: :canceled)]
        end

73
        it { is_expected.to eq 'failed' }
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
      end

      context 'one failed but allowed to fail and one canceled' do
        let(:statuses) do
          [create(type, status: :failed, allow_failure: true),
           create(type, status: :canceled)]
        end

        it { is_expected.to eq 'canceled' }
      end

      context 'one running one canceled' do
        let(:statuses) do
          [create(type, status: :running), create(type, status: :canceled)]
        end

        it { is_expected.to eq 'running' }
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
      end

      context 'all canceled' do
        let(:statuses) do
          [create(type, status: :canceled), create(type, status: :canceled)]
        end
        it { is_expected.to eq 'canceled' }
      end

      context 'success and canceled but allowed to fail' do
        let(:statuses) do
          [create(type, status: :success),
           create(type, status: :canceled, allow_failure: true)]
        end

        it { is_expected.to eq 'success' }
      end

109 110 111 112
      context 'one finished and second running but allowed to fail' do
        let(:statuses) do
          [create(type, status: :success),
           create(type, status: :running, allow_failure: true)]
113
        end
114 115

        it { is_expected.to eq 'running' }
116
      end
117
    end
118 119 120 121 122 123 124 125 126 127

    context 'ci build statuses' do
      let(:type) { :ci_build }
      it_behaves_like 'build status summary'
    end

    context 'generic commit statuses' do
      let(:type) { :generic_commit_status }
      it_behaves_like 'build status summary'
    end
128 129
  end
end