blob: 9e5099ce79687d0d1019731e76fd84d38828dcec (
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
require 'spec_helper'
describe Ci::Build::Eraseable, models: true do
shared_examples 'eraseable' do
it 'should remove artifact file' do
expect(build.artifacts_file.exists?).to be_falsy
end
it 'should remove artifact metadata file' do
expect(build.artifacts_metadata.exists?).to be_falsy
end
it 'should erase build trace in trace file' do
expect(build.trace).to be_empty
end
it 'should set erased to true' do
expect(build.erased?).to be true
end
it 'should set erase date' do
expect(build.erased_at).to_not be_falsy
end
end
context 'build is not eraseable' do
let!(:build) { create(:ci_build) }
describe '#erase!' do
it { expect { build.erase! }.to raise_error(StandardError, /Build not eraseable!/ )}
end
describe '#eraseable?' do
subject { build.eraseable? }
it { is_expected.to eq false }
end
describe '#erase_url' do
subject { build.erase_url }
it { is_expected.to be_falsy }
end
end
context 'build is eraseable' do
let!(:build) { create(:ci_build_with_trace, :success, :artifacts) }
describe '#erase!' do
before { build.erase!(erased_by: user) }
context 'erased by user' do
let!(:user) { create(:user, username: 'eraser') }
include_examples 'eraseable'
it 'should record user who erased a build' do
expect(build.erased_by).to eq user
end
end
context 'erased by system' do
let(:user) { nil }
include_examples 'eraseable'
it 'should not set user who erased a build' do
expect(build.erased_by).to be_nil
end
end
end
describe '#eraseable?' do
subject { build.eraseable? }
it { is_expected.to eq true }
end
describe '#erase_url' do
subject { build.erase_url }
it { is_expected.to be_truthy }
end
describe '#erased?' do
let!(:build) { create(:ci_build_with_trace, :success, :artifacts) }
subject { build.erased? }
context 'build has not been erased' do
it { is_expected.to be false }
end
context 'build has been erased' do
before { build.erase! }
it { is_expected.to be true }
end
end
context 'metadata and build trace are not available' do
let!(:build) { create(:ci_build, :success, :artifacts) }
before { build.remove_artifacts_metadata! }
describe '#erase!' do
it 'should not raise error' do
expect { build.erase! }.to_not raise_error
end
end
end
end
end
|