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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# frozen_string_literal: true
require 'spec_helper'
describe Deployments::OlderDeploymentsDropService do
let(:environment) { create(:environment) }
let(:deployment) { create(:deployment, environment: environment) }
let(:service) { described_class.new(deployment) }
describe '#execute' do
subject { service.execute }
shared_examples 'it does not drop any build' do
it do
expect { subject }.to not_change(Ci::Build.failed, :count)
end
end
context 'when deployment is nil' do
let(:deployment) { nil }
it_behaves_like 'it does not drop any build'
end
context 'when a deployment is passed in' do
context 'and there is no active deployment for the related environment' do
let(:deployment) { create(:deployment, :canceled, environment: environment) }
let(:deployment2) { create(:deployment, :canceled, environment: environment) }
before do
deployment
deployment2
end
it_behaves_like 'it does not drop any build'
end
context 'and there are active deployment for the related environment' do
let(:deployment) { create(:deployment, :running, environment: environment) }
let(:deployment2) { create(:deployment, :running, environment: environment) }
context 'and there is no older deployment than "deployment"' do
before do
deployment
deployment2
end
it_behaves_like 'it does not drop any build'
end
context 'and there is an older deployment than "deployment"' do
let(:older_deployment) { create(:deployment, :running, environment: environment) }
before do
older_deployment
deployment
deployment2
end
it 'drops that older deployment' do
deployable = older_deployment.deployable
expect(deployable.failed?).to be_falsey
subject
expect(deployable.reload.failed?).to be_truthy
end
context 'and there is no deployable for that older deployment' do
let(:older_deployment) { create(:deployment, :running, environment: environment, deployable: nil) }
it_behaves_like 'it does not drop any build'
end
end
end
end
end
end
|