summaryrefslogtreecommitdiff
path: root/spec/models/ci/build_pending_state_spec.rb
blob: 756180621ec09fbae2cf3e5a354356da8b83392a (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::BuildPendingState do
  describe '#crc32' do
    context 'when checksum does not exist' do
      let(:pending_state) do
        build(:ci_build_pending_state, trace_checksum: nil)
      end

      it 'returns nil' do
        expect(pending_state.crc32).to be_nil
      end
    end

    context 'when checksum is in hexadecimal' do
      let(:pending_state) do
        build(:ci_build_pending_state, trace_checksum: 'crc32:75bcd15')
      end

      it 'returns decimal representation of the checksum' do
        expect(pending_state.crc32).to eq 123456789
      end
    end
  end

  describe 'partitioning' do
    context 'with build' do
      let(:build) { FactoryBot.build(:ci_build, partition_id: ci_testing_partition_id) }
      let(:build_pending_state) { FactoryBot.build(:ci_build_pending_state, build: build) }

      it 'sets partition_id to the current partition value' do
        expect { build_pending_state.valid? }.to change { build_pending_state.partition_id }.to(ci_testing_partition_id)
      end

      context 'when it is already set' do
        let(:build_pending_state) { FactoryBot.build(:ci_build_pending_state, partition_id: 125) }

        it 'does not change the partition_id value' do
          expect { build_pending_state.valid? }.not_to change { build_pending_state.partition_id }
        end
      end
    end

    context 'without build' do
      let(:build_pending_state) { FactoryBot.build(:ci_build_pending_state, build: nil) }

      it { is_expected.to validate_presence_of(:partition_id) }

      it 'does not change the partition_id value' do
        expect { build_pending_state.valid? }.not_to change { build_pending_state.partition_id }
      end
    end
  end
end