Skip to content
This repository has been archived by the owner on Nov 11, 2017. It is now read-only.

Commit

Permalink
Include non-standard ports in request URL sent to notifier.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandunn committed Dec 8, 2009
1 parent ee88dfd commit cc6d310
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
12 changes: 11 additions & 1 deletion lib/hoptoad_notifier/catcher.rb
Expand Up @@ -60,7 +60,7 @@ def request_data_for_hoptoad
:session_data => session_data, :session_data => session_data,
:controller => params[:controller], :controller => params[:controller],
:action => params[:action], :action => params[:action],
:url => "#{request.protocol}#{request.host}#{request.request_uri}", :url => request_url,
:cgi_data => filter_if_filtering(request.env), :cgi_data => filter_if_filtering(request.env),
:environment_vars => filter_if_filtering(ENV) } :environment_vars => filter_if_filtering(ENV) }
end end
Expand All @@ -81,5 +81,15 @@ def session_data
end end
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
end end
29 changes: 27 additions & 2 deletions test/catcher_test.rb
Expand Up @@ -43,11 +43,21 @@ def assert_sent_request_info_for(request)
assert_sent_hash params, '/notice/request/params' assert_sent_hash params, '/notice/request/params'
assert_sent_element params['controller'], '/notice/request/component' assert_sent_element params['controller'], '/notice/request/component'
assert_sent_element params['action'], '/notice/request/action' assert_sent_element params['action'], '/notice/request/action'
assert_sent_element "#{request.protocol}#{request.host}#{request.request_uri}", assert_sent_element url_from_request(request), '/notice/request/url'
'/notice/request/url'
assert_sent_hash request.env, '/notice/request/cgi-data' assert_sent_hash request.env, '/notice/request/cgi-data'
end 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 def sender
HoptoadNotifier.sender HoptoadNotifier.sender
end end
Expand Down Expand Up @@ -81,6 +91,9 @@ def local_request?
opts[:request].env["HTTP_USER_AGENT"] = opts[:user_agent] opts[:request].env["HTTP_USER_AGENT"] = opts[:user_agent]
end end
end end
if opts[:port]
opts[:request].port = opts[:port]
end
klass.consider_all_requests_local = opts[:all_local] klass.consider_all_requests_local = opts[:all_local]
klass.local = opts[:local] klass.local = opts[:local]
controller = klass.new controller = klass.new
Expand Down Expand Up @@ -198,12 +211,24 @@ def process_action_with_automatic_notification(args = {})
assert_sent_request_info_for controller.request assert_sent_request_info_for controller.request
end 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 should "send request data for automatic notification" do
params = { 'controller' => "hoptoad_test", 'action' => "index" } params = { 'controller' => "hoptoad_test", 'action' => "index" }
controller = process_action_with_automatic_notification(:params => params) controller = process_action_with_automatic_notification(:params => params)
assert_sent_request_info_for controller.request assert_sent_request_info_for controller.request
end 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 should "use standard rails logging filters on params and env" do
filtered_params = { "abc" => "123", filtered_params = { "abc" => "123",
"def" => "456", "def" => "456",
Expand Down

0 comments on commit cc6d310

Please sign in to comment.