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:
Markus Doits 2018-09-15 12:58:44 +02:00
parent e7df959b8f
commit d71a779740
No known key found for this signature in database
GPG key ID: A0796D16BD3D3DAE
2 changed files with 19 additions and 2 deletions

View file

@ -320,7 +320,8 @@ module Ci
end
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
def latest?

View file

@ -1472,7 +1472,7 @@ describe Ci::Build do
end
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 }) }
it 'returns a number of configured max retries' do
@ -1480,6 +1480,22 @@ describe Ci::Build do
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
subject { create(:ci_build) }