summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil TrzciƄski <ayufan@ayufan.eu>2018-03-20 09:57:36 +0000
committerMayra Cabrera <mcabrera@gitlab.com>2018-03-23 10:19:12 -0600
commit551321026da6e84f4bfb104a00d647fc09921fd2 (patch)
tree8aeb252a2ed6839f4fc77fad38e35bab0b089fa5
parente9613d4a760689d1b55d0735a08b159c1dc5b378 (diff)
downloadgitlab-ce-551321026da6e84f4bfb104a00d647fc09921fd2.tar.gz
Merge branch 'fix/sm/erase_old_trace' into 'master'
Use update_column than write_attribute and save Closes #44366 See merge request gitlab-org/gitlab-ce!17861
-rw-r--r--app/models/ci/build.rb3
-rw-r--r--spec/lib/gitlab/ci/trace_spec.rb22
2 files changed, 23 insertions, 2 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 5a381bdd6a2..62e59dc2e8f 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -328,8 +328,7 @@ module Ci
end
def erase_old_trace!
- write_attribute(:trace, nil)
- save
+ update_column(:trace, nil)
end
def needs_touch?
diff --git a/spec/lib/gitlab/ci/trace_spec.rb b/spec/lib/gitlab/ci/trace_spec.rb
index 448c6fb57dd..3a9371ed2e8 100644
--- a/spec/lib/gitlab/ci/trace_spec.rb
+++ b/spec/lib/gitlab/ci/trace_spec.rb
@@ -510,6 +510,28 @@ describe Gitlab::Ci::Trace do
it_behaves_like 'source trace in database stays intact', error: ActiveRecord::RecordInvalid
end
+
+ context 'when there is a validation error on Ci::Build' do
+ before do
+ allow_any_instance_of(Ci::Build).to receive(:save).and_return(false)
+ allow_any_instance_of(Ci::Build).to receive_message_chain(:errors, :full_messages)
+ .and_return(%w[Error Error])
+ end
+
+ context "when erase old trace with 'save'" do
+ before do
+ build.send(:write_attribute, :trace, nil)
+ build.save
+ end
+
+ it 'old trace is not deleted' do
+ build.reload
+ expect(build.trace.raw).to eq(trace_content)
+ end
+ end
+
+ it_behaves_like 'archive trace in database'
+ end
end
end