Commit c850ceec authored by Grzegorz Bizon's avatar Grzegorz Bizon Committed by Grzegorz Bizon

Create method that checks if build has been erased

+ minor improvements
parent 433de7ba
......@@ -26,16 +26,18 @@ module Ci
end
end
def erased?
!self.erased_at.nil?
end
private
def erase_trace!
File.truncate(path_to_trace, 0) if File.file?(path_to_trace)
self.trace = nil
end
def update_erased!(user = nil)
self.erased_by = user if user
self.erased_at = Time.now
self.save!
self.update(erased_by: user, erased_at: Time.now)
end
end
end
......
......@@ -18,7 +18,7 @@ class Spinach::Features::ProjectBuildsSummary < Spinach::FeatureSteps
step 'recent build has been erased' do
expect(@build.artifacts_file.exists?).to be_falsy
expect(@build.artifacts_metadata.exists?).to be_falsy
expect(File.zero?(@build.path_to_trace)).to be true
expect(@build.trace).to be_empty
end
step 'recent build summary does not have artifacts widget' do
......
......@@ -11,7 +11,7 @@ describe Ci::Build::Eraseable, models: true do
end
it 'should erase build trace in trace file' do
expect(File.zero?(build.path_to_trace)).to eq true
expect(build.trace).to be_empty
end
it 'should set erased to true' do
......@@ -78,6 +78,21 @@ describe Ci::Build::Eraseable, models: true do
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! }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment