diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-12-25 09:34:01 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-12-25 09:34:01 +0000 |
commit | 64799454a2186596c70324db2958d0fc231d6f1b (patch) | |
tree | 10f88f448ec717a572c4a0d55b2d672494d4478a | |
parent | c6b4c8d240abbca0d1e62b3544fafda77c40de0c (diff) | |
download | rails-64799454a2186596c70324db2958d0fc231d6f1b.tar.gz rails-64799454a2186596c70324db2958d0fc231d6f1b.tar.bz2 rails-64799454a2186596c70324db2958d0fc231d6f1b.zip |
Fix assert_redirected_to bug where redirecting from a nested to to a top-level controller incorrectly added the current controller's nesting. Closes #6128. [Rick Olson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5785 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | actionpack/lib/action_controller/assertions/response_assertions.rb | 4 | ||||
-rw-r--r-- | actionpack/test/controller/action_pack_assertions_test.rb | 24 | ||||
-rw-r--r-- | actionpack/test/controller/test_test.rb | 2 |
3 files changed, 26 insertions, 4 deletions
diff --git a/actionpack/lib/action_controller/assertions/response_assertions.rb b/actionpack/lib/action_controller/assertions/response_assertions.rb index c0b78552f2..0811920e4a 100644 --- a/actionpack/lib/action_controller/assertions/response_assertions.rb +++ b/actionpack/lib/action_controller/assertions/response_assertions.rb @@ -70,14 +70,14 @@ module ActionController if value.respond_to?(:[]) && value['controller'] if key == :actual && value['controller'].first != '/' && !value['controller'].include?('/') - value['controller'] = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.controller_path) + new_controller_path = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.controller_path) + value['controller'] = new_controller_path if value['controller'] != new_controller_path && ActionController::Routing.possible_controllers.include?(new_controller_path) end value['controller'] = value['controller'][1..-1] if value['controller'].first == '/' # strip leading hash end url[key] = value end - @response_diff = url[:expected].diff(url[:actual]) if url[:actual] msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is <?>), difference: <?>", url[:actual], @response_diff) diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 5f5e1dca26..21930aa061 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -139,6 +139,10 @@ module Admin def redirect_to_fellow_controller redirect_to :controller => 'user' end + + def redirect_to_top_level_named_route + redirect_to top_level_url(:id => "foo") + end end end @@ -150,15 +154,20 @@ end # production environment ActionPackAssertionsController.template_root = File.dirname(__FILE__) + "/../fixtures/" - # a test case to exercise the new capabilities TestRequest & TestResponse class ActionPackAssertionsControllerTest < Test::Unit::TestCase # let's get this party started def setup + ActionController::Routing::Routes.reload + ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module content admin/user)) @controller = ActionPackAssertionsController.new @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new end + def teardown + ActionController::Routing::Routes.reload + end + # -- assertion-based testing ------------------------------------------------ def test_assert_tag_and_url_for @@ -294,6 +303,19 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase assert_redirected_to admin_inner_module_path end end + + def test_assert_redirected_to_top_level_named_route_from_nested_controller + with_routing do |set| + set.draw do |map| + map.top_level '/action_pack_assertions/:id', :controller => 'action_pack_assertions', :action => 'index' + map.connect ':controller/:action/:id' + end + @controller = Admin::InnerModuleController.new + process :redirect_to_top_level_named_route + # passes -> assert_redirected_to "http://test.host/action_pack_assertions/foo" + assert_redirected_to "/action_pack_assertions/foo" + end + end # test the flash-based assertions with something is in the flash def test_flash_assertions_full diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index bc2651c281..2b0086c5f4 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -86,7 +86,7 @@ HTML @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new ActionController::Routing::Routes.reload - ActionController::Routing.use_controllers! %w(content admin/user) + ActionController::Routing.use_controllers! %w(content admin/user test_test/test) end def teardown |