blob: abf31dd51847545c6bb12fdc4a617c3be7b569b0 (
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, feature_category: :continuous_integration 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
|