Skip to content

Commit

Permalink
fix webhook notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
smartinez87 committed Jul 17, 2016
1 parent 348dff6 commit 4c95065
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/exception_notifier/webhook_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def call(exception, options={})
options[:body][:session] = request.session
options[:body][:environment] = request.filtered_env
end
send_notice(exception, options, nil, @default_options) do |msg, opts|
HTTParty.send(http_method, url, opts)
send_notice(exception, options, nil, @default_options) do |_, _|
HTTParty.send(http_method, url, options)
end
end
end
Expand Down
30 changes: 28 additions & 2 deletions test/exception_notifier/webhook_notifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class WebhookNotifierTest < ActiveSupport::TestCase
assert_equal response[:body][:exception][:error_class], "ZeroDivisionError"
assert_includes response[:body][:exception][:message], "divided by 0"
assert_includes response[:body][:exception][:backtrace], "/exception_notification/test/webhook_notifier_test.rb:48"

assert response[:body][:request][:cookies].has_key?(:cookie_item1)
assert_equal response[:body][:request][:url], "http://example.com/example"
assert_equal response[:body][:request][:ip_address], "192.168.1.1"
Expand All @@ -25,6 +25,16 @@ class WebhookNotifierTest < ActiveSupport::TestCase
assert response[:body][:data][:extra_data].has_key?(:data_item1)
end

test "should send webhook notification with correct params data" do
url = 'http://localhost:8000'
fake_exception.stubs(:backtrace).returns('the backtrace')
webhook = ExceptionNotifier::WebhookNotifier.new({:url => url})

HTTParty.expects(:send).with(:post, url, fake_params)

webhook.call(fake_exception)
end

test "should call pre/post_callback if specified" do
HTTParty.stubs(:send).returns(fake_response)
webhook = ExceptionNotifier::WebhookNotifier.new({:url => 'http://localhost:8000'})
Expand Down Expand Up @@ -58,8 +68,24 @@ def fake_response
}
end

def fake_params
{
:body => {
:server => Socket.gethostname,
:process => $$,
:rails_root => Rails.root,
:exception => {
:error_class => 'ZeroDivisionError',
:message => 'divided by 0'.inspect,
:backtrace => 'the backtrace'
},
:data => {}
}
}
end

def fake_exception
begin
@fake_exception ||= begin
5/0
rescue Exception => e
e
Expand Down

0 comments on commit 4c95065

Please sign in to comment.