summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-01-19 18:49:14 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-01-19 18:49:14 +0100
commit86217866fda66cb770ee8c9a540bf535a980eb36 (patch)
treefad8e0caec1c292628ac0a81db4beb3996b7321e
parent73fcfb296c90746f868ec11a19477a16039ef9a5 (diff)
downloadgitlab-ce-feature/success-warning-icons-in-stages-builds.tar.gz
Fix warnings argument memoization in CI/CD stagefeature/success-warning-icons-in-stages-builds
-rw-r--r--app/models/ci/stage.rb6
-rw-r--r--spec/models/ci/stage_spec.rb24
2 files changed, 24 insertions, 6 deletions
diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb
index ca76d82f358..ca74c91b062 100644
--- a/app/models/ci/stage.rb
+++ b/app/models/ci/stage.rb
@@ -46,7 +46,11 @@ module Ci
end
def has_warnings?
- @warnings ||= statuses.latest.failed_but_allowed.any?
+ if @warnings.nil?
+ statuses.latest.failed_but_allowed.any?
+ else
+ @warnings
+ end
end
end
end
diff --git a/spec/models/ci/stage_spec.rb b/spec/models/ci/stage_spec.rb
index cca0cb1e3b0..c4a9743a4e2 100644
--- a/spec/models/ci/stage_spec.rb
+++ b/spec/models/ci/stage_spec.rb
@@ -169,10 +169,22 @@ describe Ci::Stage, models: true do
describe '#has_warnings?' do
context 'when stage has warnings' do
context 'when using memoized warnings flag' do
- let(:stage) { build(:ci_stage, warnings: true) }
+ context 'when there are warnings' do
+ let(:stage) { build(:ci_stage, warnings: true) }
- it 'has warnings' do
- expect(stage).to have_warnings
+ it 'has memoized warnings' do
+ expect(stage).not_to receive(:statuses)
+ expect(stage).to have_warnings
+ end
+ end
+
+ context 'when there are no warnings' do
+ let(:stage) { build(:ci_stage, warnings: false) }
+
+ it 'has memoized warnings' do
+ expect(stage).not_to receive(:statuses)
+ expect(stage).not_to have_warnings
+ end
end
end
@@ -182,7 +194,8 @@ describe Ci::Stage, models: true do
stage: stage_name, pipeline: pipeline)
end
- it 'has warnings' do
+ it 'has warnings calculated from statuses' do
+ expect(stage).to receive(:statuses).and_call_original
expect(stage).to have_warnings
end
end
@@ -194,7 +207,8 @@ describe Ci::Stage, models: true do
pipeline: pipeline)
end
- it 'does not have warnings' do
+ it 'does not have warnings calculated from statuses' do
+ expect(stage).to receive(:statuses).and_call_original
expect(stage).not_to have_warnings
end
end