Permalink
Browse files

Fix assert_redirected_to issue with named routes for module controlle…

…rs. [Rick Olson]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4757 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent c963f8e commit 8c4b599b7c62b85069fa04533e8f06e5476f927a @technoweenie technoweenie committed Aug 13, 2006
View
@@ -1,5 +1,7 @@
*SVN*
+* Fix assert_redirected_to issue with named routes for module controllers. [Rick Olson]
+
* Tweak RoutingError message to show option diffs, not just missing named route significant keys. [Rick Olson]
* Invoke method_missing directly on hidden actions. Closes #3030. [Nicholas Seckar]
@@ -108,13 +108,14 @@ def assert_redirected_to(options = {}, message=nil)
end
if value.respond_to?(:[]) && value['controller']
- if key == :actual && value['controller'].first != '/'
+ if key == :actual && value['controller'].first != '/' && !value['controller'].include?('/')
value['controller'] = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.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: <?>",
@@ -124,9 +124,18 @@ def rescue_action(e) raise; end
module Admin
class InnerModuleController < ActionController::Base
+ def index
+ render :nothing => true
+ end
+
+ def redirect_to_index
+ redirect_to admin_inner_module_path
+ end
+
def redirect_to_absolute_controller
redirect_to :controller => '/content'
end
+
def redirect_to_fellow_controller
redirect_to :controller => 'user'
end
@@ -267,6 +276,19 @@ def test_assert_redirect_to_named_route_failure
end
end
+ def test_assert_redirect_to_nested_named_route
+ with_routing do |set|
+ set.draw do |map|
+ map.admin_inner_module 'admin/inner_module', :controller => 'admin/inner_module', :action => 'index'
+ map.connect ':controller/:action/:id'
+ end
+ @controller = Admin::InnerModuleController.new
+ process :redirect_to_index
+ # redirection is <{"action"=>"index", "controller"=>"admin/admin/inner_module"}>
+ assert_redirected_to admin_inner_module_path
+ end
+ end
+
# test the flash-based assertions with something is in the flash
def test_flash_assertions_full
process :flash_me
@@ -134,6 +134,13 @@ def test_named_route_with_default
end
+ def test_named_route_with_nested_controller
+ rs.add_named_route :users, 'admin/user', :controller => '/admin/user', :action => 'index'
+ x = setup_for_named_route.new
+ assert_equal({:controller => '/admin/user', :action => 'index', :use_route => :users},
+ x.send(:users_url))
+ end
+
def setup_for_named_route
x = Class.new
x.send(:define_method, :url_for) {|x| x}
@@ -1177,6 +1184,7 @@ def setup_named_route_test
map.show '/people/:id', :controller => 'people', :action => 'show'
map.index '/people', :controller => 'people', :action => 'index'
map.multi '/people/go/:foo/:bar/joe/:id', :controller => 'people', :action => 'multi'
+ map.users '/admin/users', :controller => 'admin/users', :action => 'index'
end
klass = Class.new(MockController)
@@ -1209,6 +1217,10 @@ def test_named_route_url_method
assert_equal "http://named.route.test/people", controller.send(:index_url)
assert_equal "/people", controller.send(:index_path)
+
+ assert_equal "http://named.route.test/admin/users", controller.send(:users_url)
+ assert_equal '/admin/users', controller.send(:users_path)
+ assert_equal '/admin/users', set.generate(controller.send(:hash_for_users_url), {:controller => 'users', :action => 'index'})
end
def test_namd_route_url_method_with_ordered_parameters

0 comments on commit 8c4b599

Please sign in to comment.