diff options
author | Eric Davis <edavis@littlestreamsoftware.com> | 2009-02-10 03:12:40 +0000 |
---|---|---|
committer | Eric Davis <edavis@littlestreamsoftware.com> | 2009-02-10 03:12:40 +0000 |
commit | 5b7a5c39a7da667b1a2718d166a80f1f0ae4d434 (patch) | |
tree | a244911585cbbaa630dedc2cdee0c87bfc056da8 /test | |
parent | a3fa56d98892650582843e7910586a064b78bba0 (diff) | |
download | redmine-5b7a5c39a7da667b1a2718d166a80f1f0ae4d434.tar.gz redmine-5b7a5c39a7da667b1a2718d166a80f1f0ae4d434.zip |
Added request and controller objects to the hooks by default.
The request and controller objects are now added to all hook contexts by
default. This will also make url_for work better in hooks by setting up
the default_url_options :host, :port, and :protocol.
Finally a new helper method @render_or@ has been added to ViewListener. This
will let a hook easily render a partial without a full method definition.
Thanks to Thomas Löber for the original patch. #2542
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2429 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/lib/redmine/hook_test.rb | 83 |
1 files changed, 79 insertions, 4 deletions
diff --git a/test/unit/lib/redmine/hook_test.rb b/test/unit/lib/redmine/hook_test.rb index 0d76374b6..12c89bf06 100644 --- a/test/unit/lib/redmine/hook_test.rb +++ b/test/unit/lib/redmine/hook_test.rb @@ -20,7 +20,7 @@ require File.dirname(__FILE__) + '/../../../test_helper' class Redmine::Hook::ManagerTest < Test::Unit::TestCase # Some hooks that are manually registered in these tests - class TestHook < Redmine::Hook::Listener; end + class TestHook < Redmine::Hook::ViewListener; end class TestHook1 < TestHook def view_layouts_base_html_head(context) @@ -39,6 +39,13 @@ class Redmine::Hook::ManagerTest < Test::Unit::TestCase "Context keys: #{context.keys.collect(&:to_s).sort.join(', ')}." end end + + class TestLinkToHook < TestHook + def view_layouts_base_html_head(context) + link_to('Issues', :controller => 'issues') + end + end + Redmine::Hook.clear_listeners def setup @@ -47,6 +54,7 @@ class Redmine::Hook::ManagerTest < Test::Unit::TestCase def teardown @hook_module.clear_listeners + @hook_module.default_url_options = { } end def test_clear_listeners @@ -67,17 +75,84 @@ class Redmine::Hook::ManagerTest < Test::Unit::TestCase def test_call_hook @hook_module.add_listener(TestHook1) - assert_equal 'Test hook 1 listener.', @hook_module.call_hook(:view_layouts_base_html_head) + assert_equal ['Test hook 1 listener.'], @hook_module.call_hook(:view_layouts_base_html_head) end def test_call_hook_with_context @hook_module.add_listener(TestHook3) - assert_equal 'Context keys: bar, foo.', @hook_module.call_hook(:view_layouts_base_html_head, :foo => 1, :bar => 'a') + assert_equal ['Context keys: bar, foo.'], @hook_module.call_hook(:view_layouts_base_html_head, :foo => 1, :bar => 'a') end def test_call_hook_with_multiple_listeners @hook_module.add_listener(TestHook1) @hook_module.add_listener(TestHook2) - assert_equal 'Test hook 1 listener.Test hook 2 listener.', @hook_module.call_hook(:view_layouts_base_html_head) + assert_equal ['Test hook 1 listener.', 'Test hook 2 listener.'], @hook_module.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'} + @hook_module.add_listener(TestLinkToHook) + + assert_equal ['<a href="http://example.com/issues">Issues</a>'], + @hook_module.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 ['<a href="http://example.com:3000/issues">Issues</a>'], + @hook_module.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 ['<a href="https://example.com/issues">Issues</a>'], + @hook_module.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 ['<a href="https://example.com/issues">Issues</a>'], + @hook_module.call_hook(:view_layouts_base_html_head, :request => request) + end + + # Context: Redmine::Hook::Helper.call_hook + def test_call_hook_with_project_added_to_context + # TODO: Implement test + end + + def test_call_hook_from_controller_with_controller_added_to_context + # TODO: Implement test + end + + def test_call_hook_from_controller_with_request_added_to_context + # TODO: Implement test + end + + def test_call_hook_from_view_with_project_added_to_context + # TODO: Implement test + end + + def test_call_hook_from_view_with_controller_added_to_context + # TODO: Implement test + end + + def test_call_hook_from_view_with_request_added_to_context + # TODO: Implement test + end + + def test_call_hook_from_view_should_join_responses_with_a_space + # TODO: Implement test end end + |