diff --git a/lib/hoptoad_notifier/catcher.rb b/lib/hoptoad_notifier/catcher.rb index cbfc00e..78f174e 100644 --- a/lib/hoptoad_notifier/catcher.rb +++ b/lib/hoptoad_notifier/catcher.rb @@ -60,7 +60,7 @@ def request_data_for_hoptoad :session_data => session_data, :controller => params[:controller], :action => params[:action], - :url => "#{request.protocol}#{request.host}#{request.request_uri}", + :url => request_url, :cgi_data => filter_if_filtering(request.env), :environment_vars => filter_if_filtering(ENV) } end @@ -81,5 +81,15 @@ def session_data end end + def request_url + url = "#{request.protocol}#{request.host}" + + unless [80, 443].include?(request.port) + url << ":#{request.port}" + end + + url << request.request_uri + url + end end end diff --git a/test/catcher_test.rb b/test/catcher_test.rb index 61d6afd..0905f27 100644 --- a/test/catcher_test.rb +++ b/test/catcher_test.rb @@ -43,11 +43,21 @@ def assert_sent_request_info_for(request) assert_sent_hash params, '/notice/request/params' assert_sent_element params['controller'], '/notice/request/component' assert_sent_element params['action'], '/notice/request/action' - assert_sent_element "#{request.protocol}#{request.host}#{request.request_uri}", - '/notice/request/url' + assert_sent_element url_from_request(request), '/notice/request/url' assert_sent_hash request.env, '/notice/request/cgi-data' end + def url_from_request(request) + url = "#{request.protocol}#{request.host}" + + unless [80, 443].include?(request.port) + url << ":#{request.port}" + end + + url << request.request_uri + url + end + def sender HoptoadNotifier.sender end @@ -81,6 +91,9 @@ def local_request? opts[:request].env["HTTP_USER_AGENT"] = opts[:user_agent] end end + if opts[:port] + opts[:request].port = opts[:port] + end klass.consider_all_requests_local = opts[:all_local] klass.local = opts[:local] controller = klass.new @@ -198,12 +211,24 @@ def process_action_with_automatic_notification(args = {}) assert_sent_request_info_for controller.request end + should "send request data for manual notification with non-standard port" do + params = { 'controller' => "hoptoad_test", 'action' => "index" } + controller = process_action_with_manual_notification(:params => params, :port => 81) + assert_sent_request_info_for controller.request + end + should "send request data for automatic notification" do params = { 'controller' => "hoptoad_test", 'action' => "index" } controller = process_action_with_automatic_notification(:params => params) assert_sent_request_info_for controller.request end + should "send request data for automatic notification with non-standard port" do + params = { 'controller' => "hoptoad_test", 'action' => "index" } + controller = process_action_with_automatic_notification(:params => params, :port => 81) + assert_sent_request_info_for controller.request + end + should "use standard rails logging filters on params and env" do filtered_params = { "abc" => "123", "def" => "456",