FIX: Wildcard webhooks could send duplicated events.

This commit is contained in:
Guo Xiang Tan 2018-01-03 17:00:44 +08:00
parent b295c03001
commit 9644569a28
2 changed files with 8 additions and 0 deletions

View File

@ -34,6 +34,7 @@ class WebHook < ActiveRecord::Base
WebHook.where(active: true)
.joins(:web_hook_event_types)
.where("web_hooks.wildcard_web_hook = ? OR web_hook_event_types.name = ?", true, type.to_s)
.uniq
end
def self.enqueue_hooks(type, opts = {})

View File

@ -43,6 +43,13 @@ describe WebHook do
end
describe '#find_by_type' do
it "returns unique hooks" do
post_hook.web_hook_event_types << WebHookEventType.find_by(name: 'topic')
post_hook.update!(wildcard_web_hook: true)
expect(WebHook.find_by_type(:post)).to eq([post_hook])
end
it 'find relevant hooks' do
expect(WebHook.find_by_type(:post)).to eq([post_hook])
expect(WebHook.find_by_type(:topic)).to eq([topic_hook])