allow retries to be a hash
- when it is a hash, retries max count is assumed to be at hash[:max] - when it is an integer, this is the max count (as before)
This commit is contained in:
parent
e7df959b8f
commit
d71a779740
2 changed files with 19 additions and 2 deletions
|
@ -320,7 +320,8 @@ module Ci
|
||||||
end
|
end
|
||||||
|
|
||||||
def retries_max
|
def retries_max
|
||||||
self.options.to_h.fetch(:retry, 0).to_i
|
retries = self.options[:retry]
|
||||||
|
retries.is_a?(Hash) && retries.fetch(:max, 0) || retries || 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def latest?
|
def latest?
|
||||||
|
|
|
@ -1472,7 +1472,7 @@ describe Ci::Build do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#retries_max' do
|
describe '#retries_max' do
|
||||||
context 'when max retries value is defined' do
|
context 'when max retries value is defined as an integer' do
|
||||||
subject { create(:ci_build, options: { retry: 1 }) }
|
subject { create(:ci_build, options: { retry: 1 }) }
|
||||||
|
|
||||||
it 'returns a number of configured max retries' do
|
it 'returns a number of configured max retries' do
|
||||||
|
@ -1480,6 +1480,22 @@ describe Ci::Build do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when retries value is defined as a hash' do
|
||||||
|
subject { create(:ci_build, options: { retry: { max: 1 } }) }
|
||||||
|
|
||||||
|
it 'returns a number of configured max retries' do
|
||||||
|
expect(subject.retries_max).to eq 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when retries value is defined as a hash without max key' do
|
||||||
|
subject { create(:ci_build, options: { retry: { something: :else } }) }
|
||||||
|
|
||||||
|
it 'returns a number of configured max retries' do
|
||||||
|
expect(subject.retries_max).to eq 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when max retries value is not defined' do
|
context 'when max retries value is not defined' do
|
||||||
subject { create(:ci_build) }
|
subject { create(:ci_build) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue