diff options
Diffstat (limited to 'spec/models/hooks')
-rw-r--r-- | spec/models/hooks/web_hook_spec.rb | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb index c68ad3bf0c4..59f4533a6c1 100644 --- a/spec/models/hooks/web_hook_spec.rb +++ b/spec/models/hooks/web_hook_spec.rb @@ -10,7 +10,11 @@ RSpec.describe WebHook do let(:hook) { build(:project_hook, project: project) } around do |example| - freeze_time { example.run } + if example.metadata[:skip_freeze_time] + example.run + else + freeze_time { example.run } + end end describe 'associations' do @@ -326,10 +330,28 @@ RSpec.describe WebHook do expect { hook.backoff! }.to change(hook, :backoff_count).by(1) end - it 'does not let the backoff count exceed the maximum failure count' do - hook.backoff_count = described_class::MAX_FAILURES + context 'when we have backed off MAX_FAILURES times' do + before do + stub_const("#{described_class}::MAX_FAILURES", 5) + 5.times { hook.backoff! } + end + + it 'does not let the backoff count exceed the maximum failure count' do + expect { hook.backoff! }.not_to change(hook, :backoff_count) + end + + it 'does not change disabled_until', :skip_freeze_time do + travel_to(hook.disabled_until - 1.minute) do + expect { hook.backoff! }.not_to change(hook, :disabled_until) + end + end - expect { hook.backoff! }.not_to change(hook, :backoff_count) + it 'changes disabled_until when it has elapsed', :skip_freeze_time do + travel_to(hook.disabled_until + 1.minute) do + expect { hook.backoff! }.to change { hook.disabled_until } + expect(hook.backoff_count).to eq(described_class::MAX_FAILURES) + end + end end include_examples 'is tolerant of invalid records' do |