summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/project_latest_successful_build_for_examples.rb
blob: a9bd23e9fc928cbef763897972f940d0e8d8fc76 (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
# frozen_string_literal: true

shared_examples 'latest successful build for sha or ref' do
  context 'with many builds' do
    let(:other_pipeline) { create_pipeline(project) }
    let(:other_build) { create_build(other_pipeline, 'test') }
    let(:build_name) { other_build.name }

    before do
      pipeline1 = create_pipeline(project)
      pipeline2 = create_pipeline(project)
      create_build(pipeline1, 'test')
      create_build(pipeline1, 'test2')
      create_build(pipeline2, 'test2')
    end

    it 'gives the latest builds from latest pipeline' do
      expect(subject).to eq(other_build)
    end
  end

  context 'with succeeded pipeline' do
    let!(:build) { create_build }
    let(:build_name) { build.name }

    context 'standalone pipeline' do
      it 'returns builds for ref for default_branch' do
        expect(subject).to eq(build)
      end

      context 'with nonexistent build' do
        let(:build_name) { 'TAIL' }

        it 'returns empty relation if the build cannot be found' do
          expect(subject).to be_nil
        end
      end
    end

    context 'with some pending pipeline' do
      before do
        create_build(create_pipeline(project, 'pending'))
      end

      it 'gives the latest build from latest pipeline' do
        expect(subject).to eq(build)
      end
    end
  end

  context 'with pending pipeline' do
    let!(:pending_build) { create_build(pipeline) }
    let(:build_name) { pending_build.name }

    before do
      pipeline.update(status: 'pending')
    end

    it 'returns empty relation' do
      expect(subject).to be_nil
    end
  end
end