This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Include non-standard ports in request URL sent to notifier.

  • Loading branch information...
1 parent ee88dfd commit cc6d310dc72428516252a6234c3b8cb05ca9243b @tristandunn tristandunn committed Dec 8, 2009
Showing with 38 additions and 3 deletions.
  1. +11 −1 lib/hoptoad_notifier/catcher.rb
  2. +27 −2 test/catcher_test.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
View
@@ -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",

0 comments on commit cc6d310

Please sign in to comment.