Skip to content

Commit

Permalink
Fix assert_redirected_to for nested controllers and named routes
Browse files Browse the repository at this point in the history
[#308 state:resolved]

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information
gtd authored and NZKoz committed Jun 3, 2008
1 parent e3c26e9 commit 025515b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Expand Up @@ -97,7 +97,7 @@ def assert_redirected_to(options = {}, message=nil)
value['controller'] = value['controller'].to_s
if key == :actual && value['controller'].first != '/' && !value['controller'].include?('/')
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)
value['controller'] = new_controller_path if value['controller'] != new_controller_path && ActionController::Routing.possible_controllers.include?(new_controller_path) && @response.redirected_to.is_a?(Hash)
end
value['controller'] = value['controller'][1..-1] if value['controller'].first == '/' # strip leading hash
end
Expand Down
23 changes: 20 additions & 3 deletions actionpack/test/controller/action_pack_assertions_test.rb
Expand Up @@ -137,6 +137,9 @@ def show
end
end

class UserController < ActionController::Base
end

module Admin
class InnerModuleController < ActionController::Base
def index
Expand Down Expand Up @@ -174,7 +177,7 @@ 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))
ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module user content admin/user))
@controller = ActionPackAssertionsController.new
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
end
Expand Down Expand Up @@ -268,7 +271,7 @@ def test_assert_redirect_to_nested_named_route
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|
Expand All @@ -277,11 +280,25 @@ def test_assert_redirected_to_top_level_named_route_from_nested_controller
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 "http://test.host/action_pack_assertions/foo" would pass because of exact match early return
assert_redirected_to "/action_pack_assertions/foo"
end
end

def test_assert_redirected_to_top_level_named_route_with_same_controller_name_in_both_namespaces
with_routing do |set|
set.draw do |map|
# this controller exists in the admin namespace as well which is the only difference from previous test
map.top_level '/user/:id', :controller => 'user', :action => 'index'
map.connect ':controller/:action/:id'
end
@controller = Admin::InnerModuleController.new
process :redirect_to_top_level_named_route
# assert_redirected_to top_level_url('foo') would pass because of exact match early return
assert_redirected_to top_level_path('foo')
end
end

# -- standard request/response object testing --------------------------------

# make sure that the template objects exist
Expand Down

0 comments on commit 025515b

Please sign in to comment.