accepts .all as a hook scope as well

This commit is contained in:
Alexis Reigel 2017-12-04 15:29:13 +01:00
parent a78abf3a00
commit a63792b724
2 changed files with 11 additions and 2 deletions

View file

@ -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

View file

@ -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