Fix warnings argument memoization in CI/CD stage

This commit is contained in:
Grzegorz Bizon 2017-01-19 18:49:14 +01:00
parent 73fcfb296c
commit 86217866fd
2 changed files with 24 additions and 6 deletions

View File

@ -46,7 +46,11 @@ module Ci
end end
def has_warnings? 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 end
end end

View File

@ -169,20 +169,33 @@ describe Ci::Stage, models: true do
describe '#has_warnings?' do describe '#has_warnings?' do
context 'when stage has warnings' do context 'when stage has warnings' do
context 'when using memoized warnings flag' do context 'when using memoized warnings flag' do
context 'when there are warnings' do
let(:stage) { build(:ci_stage, warnings: true) } let(:stage) { build(:ci_stage, warnings: true) }
it 'has warnings' do it 'has memoized warnings' do
expect(stage).not_to receive(:statuses)
expect(stage).to have_warnings expect(stage).to have_warnings
end end
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
context 'when calculating warnings from statuses' do context 'when calculating warnings from statuses' do
before do before do
create(:ci_build, :failed, :allowed_to_fail, create(:ci_build, :failed, :allowed_to_fail,
stage: stage_name, pipeline: pipeline) stage: stage_name, pipeline: pipeline)
end 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 expect(stage).to have_warnings
end end
end end
@ -194,7 +207,8 @@ describe Ci::Stage, models: true do
pipeline: pipeline) pipeline: pipeline)
end 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 expect(stage).not_to have_warnings
end end
end end