2011-12-14 16:38:52 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe WebHook do
|
2017-04-27 10:08:57 +00:00
|
|
|
let(:hook) { build(:project_hook) }
|
|
|
|
|
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to have_many(:web_hook_logs).dependent(:destroy) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
2015-02-12 18:17:35 +00:00
|
|
|
it { is_expected.to validate_presence_of(:url) }
|
2011-12-14 16:38:52 +00:00
|
|
|
|
2016-02-22 12:55:36 +00:00
|
|
|
describe 'url' do
|
2017-04-27 10:08:57 +00:00
|
|
|
it { is_expected.to allow_value('http://example.com').for(:url) }
|
|
|
|
it { is_expected.to allow_value('https://example.com').for(:url) }
|
|
|
|
it { is_expected.to allow_value(' https://example.com ').for(:url) }
|
|
|
|
it { is_expected.to allow_value('http://test.com/api').for(:url) }
|
|
|
|
it { is_expected.to allow_value('http://test.com/api?key=abc').for(:url) }
|
|
|
|
it { is_expected.to allow_value('http://test.com/api?key=abc&type=def').for(:url) }
|
2011-12-14 16:38:52 +00:00
|
|
|
|
2017-04-27 10:08:57 +00:00
|
|
|
it { is_expected.not_to allow_value('example.com').for(:url) }
|
|
|
|
it { is_expected.not_to allow_value('ftp://example.com').for(:url) }
|
|
|
|
it { is_expected.not_to allow_value('herp-and-derp').for(:url) }
|
2016-02-22 12:55:36 +00:00
|
|
|
|
|
|
|
it 'strips :url before saving it' do
|
2017-04-27 10:08:57 +00:00
|
|
|
hook.url = ' https://example.com '
|
|
|
|
hook.save
|
2016-02-22 12:55:36 +00:00
|
|
|
|
|
|
|
expect(hook.url).to eq('https://example.com')
|
|
|
|
end
|
2011-12-14 16:38:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-27 10:08:57 +00:00
|
|
|
describe 'execute' do
|
|
|
|
let(:data) { { key: 'value' } }
|
|
|
|
let(:hook_name) { 'project hook' }
|
2015-12-02 00:15:01 +00:00
|
|
|
|
2017-04-27 10:08:57 +00:00
|
|
|
before do
|
|
|
|
expect(WebHookService).to receive(:new).with(hook, data, hook_name).and_call_original
|
2015-12-02 00:15:01 +00:00
|
|
|
end
|
2016-01-07 14:28:24 +00:00
|
|
|
|
2017-04-27 10:08:57 +00:00
|
|
|
it '#execute' do
|
|
|
|
expect_any_instance_of(WebHookService).to receive(:execute)
|
2016-01-07 14:28:24 +00:00
|
|
|
|
2017-04-27 10:08:57 +00:00
|
|
|
hook.execute(data, hook_name)
|
2016-01-07 14:28:24 +00:00
|
|
|
end
|
|
|
|
|
2017-04-27 10:08:57 +00:00
|
|
|
it '#async_execute' do
|
|
|
|
expect_any_instance_of(WebHookService).to receive(:async_execute)
|
2016-01-07 14:28:24 +00:00
|
|
|
|
2017-04-27 10:08:57 +00:00
|
|
|
hook.async_execute(data, hook_name)
|
2016-01-07 14:28:24 +00:00
|
|
|
end
|
2011-12-14 16:38:52 +00:00
|
|
|
end
|
|
|
|
end
|