From 9a986ac0a51fe844eee816325e6a6d4122136d9a Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Sat, 21 Feb 2009 00:23:28 +0000 Subject: [PATCH] Refactored the mess known as Hook default_url_options in favor of the simpler :only_path as suggested by splatteal on GitHub. #2542 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2491 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/hook.rb | 11 +-------- test/unit/lib/redmine/hook_test.rb | 36 +++--------------------------- 2 files changed, 4 insertions(+), 43 deletions(-) diff --git a/lib/redmine/hook.rb b/lib/redmine/hook.rb index bcd23b64f..63d7a5961 100644 --- a/lib/redmine/hook.rb +++ b/lib/redmine/hook.rb @@ -60,16 +60,7 @@ module Redmine returning [] do |response| hls = hook_listeners(hook) if hls.any? - request = context[:request] - if request - default_url_options[:host] ||= request.env["SERVER_NAME"] - # Only set port if it's requested and isn't port 80. Otherwise a url - # like: +http://example.com:/url+ may be generated - if request.env["SERVER_PORT"] && request.env["SERVER_PORT"] != 80 - default_url_options[:port] ||= request.env["SERVER_PORT"] - end - default_url_options[:protocol] ||= request.protocol - end + default_url_options[:only_path] ||= true hls.each {|listener| response << listener.send(hook, context)} end end diff --git a/test/unit/lib/redmine/hook_test.rb b/test/unit/lib/redmine/hook_test.rb index 5ebe1e757..3e70c1c69 100644 --- a/test/unit/lib/redmine/hook_test.rb +++ b/test/unit/lib/redmine/hook_test.rb @@ -100,41 +100,11 @@ class Redmine::Hook::ManagerTest < Test::Unit::TestCase assert_equal ['Test hook 1 listener.', 'Test hook 2 listener.'], @hook_helper.call_hook(:view_layouts_base_html_head) end - # Context: Redmine::Hook::call_hook - def test_call_hook_default_url_options_set - request = ActionController::TestRequest.new - request.env = { "SERVER_NAME" => 'example.com'} + # Context: Redmine::Hook::Helper.call_hook default_url + def test_call_hook_default_url_options @hook_module.add_listener(TestLinkToHook) - assert_equal ['Issues'], - @hook_helper.call_hook(:view_layouts_base_html_head, :request => request) - end - - def test_call_hook_default_url_options_set_with_no_standard_request_port - request = ActionController::TestRequest.new - request.env = { "SERVER_NAME" => 'example.com', "SERVER_PORT" => 3000} - @hook_module.add_listener(TestLinkToHook) - - assert_equal ['Issues'], - @hook_helper.call_hook(:view_layouts_base_html_head, :request => request) - end - - def test_call_hook_default_url_options_set_with_ssl - request = ActionController::TestRequest.new - request.env = { "SERVER_NAME" => 'example.com', "HTTPS" => 'on'} - @hook_module.add_listener(TestLinkToHook) - - assert_equal ['Issues'], - @hook_helper.call_hook(:view_layouts_base_html_head, :request => request) - end - - def test_call_hook_default_url_options_set_with_forwarded_ssl - request = ActionController::TestRequest.new - request.env = { "SERVER_NAME" => 'example.com', "HTTP_X_FORWARDED_PROTO" => "https"} - @hook_module.add_listener(TestLinkToHook) - - assert_equal ['Issues'], - @hook_helper.call_hook(:view_layouts_base_html_head, :request => request) + assert_equal ['Issues'], @hook_helper.call_hook(:view_layouts_base_html_head) end # Context: Redmine::Hook::Helper.call_hook