Commit d71a7797 authored by Markus Doits's avatar Markus Doits

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)
parent e7df959b
......@@ -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?
......
......@@ -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) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment