Commit a63792b7 authored by Alexis Reigel's avatar Alexis Reigel

accepts `.all` as a hook scope as well

parent a78abf3a
...@@ -18,7 +18,8 @@ module TriggerableHooks ...@@ -18,7 +18,8 @@ module TriggerableHooks
attr_reader :triggerable_hooks attr_reader :triggerable_hooks
def hooks_for(trigger) def hooks_for(trigger)
return none unless self::TRIGGERS.keys.include?(trigger) callable_scopes = self::TRIGGERS.keys + [:all]
return none unless callable_scopes.include?(trigger)
public_send(trigger) # rubocop:disable GitlabSecurity/PublicSend public_send(trigger) # rubocop:disable GitlabSecurity/PublicSend
end end
......
...@@ -26,10 +26,18 @@ RSpec.describe TriggerableHooks do ...@@ -26,10 +26,18 @@ RSpec.describe TriggerableHooks do
context 'the model does not have the required trigger scope' do context 'the model does not have the required trigger scope' do
it 'returns an empty relation' do it 'returns an empty relation' do
TestableHook.create!(url: 'http://example.com', push_events: true) TestableHook.create!(url: 'http://example.com')
expect(TestableHook.hooks_for(:tag_push_hooks)).to eq [] expect(TestableHook.hooks_for(:tag_push_hooks)).to eq []
end end
end end
context 'the stock scope ".all" is accepted' do
it 'returns the record' do
hook = TestableHook.create!(url: 'http://example.com')
expect(TestableHook.hooks_for(:all)).to eq [hook]
end
end
end end
end end
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