Welcome to mirror list, hosted at ThFree Co, Russian Federation.

update_pending_build_service_spec.rb « ci « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e49b22299f060a8dde9bc364a63f3303bed35da5 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::UpdatePendingBuildService do
  let_it_be(:group) { create(:group) }
  let_it_be(:project) { create(:project, namespace: group) }
  let_it_be_with_reload(:pending_build_1) { create(:ci_pending_build, project: project, instance_runners_enabled: false) }
  let_it_be_with_reload(:pending_build_2) { create(:ci_pending_build, project: project, instance_runners_enabled: true) }
  let_it_be(:update_params) { { instance_runners_enabled: true } }

  let(:service) { described_class.new(model, update_params) }

  describe '#execute' do
    subject(:update_pending_builds) { service.execute }

    context 'validations' do
      context 'when model is invalid' do
        let(:model) { pending_build_1 }

        it 'raises an error' do
          expect { update_pending_builds }.to raise_error(described_class::InvalidModelError)
        end
      end

      context 'when params is invalid' do
        let(:model) { group }
        let(:update_params) { { minutes_exceeded: true } }

        it 'raises an error' do
          expect { update_pending_builds }.to raise_error(described_class::InvalidParamsError)
        end
      end
    end

    context 'when model is a group with pending builds' do
      let(:model) { group }

      it 'updates all pending builds', :aggregate_failures do
        update_pending_builds

        expect(pending_build_1.instance_runners_enabled).to be_truthy
        expect(pending_build_2.instance_runners_enabled).to be_truthy
      end
    end

    context 'when model is a project with pending builds' do
      let(:model) { project }

      it 'updates all pending builds', :aggregate_failures do
        update_pending_builds

        expect(pending_build_1.instance_runners_enabled).to be_truthy
        expect(pending_build_2.instance_runners_enabled).to be_truthy
      end
    end
  end
end