2017-12-04 10:18:54 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe TriggerableHooks do
|
|
|
|
before do
|
|
|
|
class TestableHook < WebHook
|
|
|
|
include TriggerableHooks
|
|
|
|
triggerable_hooks only: [:push_hooks]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'scopes' do
|
|
|
|
it 'defines a scope for each of the requested triggers' do
|
|
|
|
expect(TestableHook).to respond_to :push_hooks
|
|
|
|
expect(TestableHook).not_to respond_to :tag_push_hooks
|
|
|
|
end
|
|
|
|
end
|
2017-12-04 11:51:39 +00:00
|
|
|
|
|
|
|
describe '.hooks_for' do
|
|
|
|
context 'the model has the required trigger scope' do
|
|
|
|
it 'returns the record' do
|
|
|
|
hook = TestableHook.create!(url: 'http://example.com', push_events: true)
|
|
|
|
|
|
|
|
expect(TestableHook.hooks_for(:push_hooks)).to eq [hook]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the model does not have the required trigger scope' do
|
|
|
|
it 'returns an empty relation' do
|
|
|
|
TestableHook.create!(url: 'http://example.com', push_events: true)
|
|
|
|
|
|
|
|
expect(TestableHook.hooks_for(:tag_push_hooks)).to eq []
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-12-04 10:18:54 +00:00
|
|
|
end
|