aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-08-13 18:31:58 +0000
committerRick Olson <technoweenie@gmail.com>2006-08-13 18:31:58 +0000
commit8c4b599b7c62b85069fa04533e8f06e5476f927a (patch)
treeb65da84b4a6f7f2104a211d8b2f905b92f5389e6 /actionpack
parentc963f8e955ca5a2d1cc668ee5fa1f7e5f1fba689 (diff)
downloadrails-8c4b599b7c62b85069fa04533e8f06e5476f927a.tar.gz
rails-8c4b599b7c62b85069fa04533e8f06e5476f927a.tar.bz2
rails-8c4b599b7c62b85069fa04533e8f06e5476f927a.zip
Fix assert_redirected_to issue with named routes for module controllers. [Rick Olson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4757 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/assertions.rb3
-rw-r--r--actionpack/test/controller/action_pack_assertions_test.rb22
-rw-r--r--actionpack/test/controller/routing_test.rb12
4 files changed, 38 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 2968661954..fae6400849 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -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]
diff --git a/actionpack/lib/action_controller/assertions.rb b/actionpack/lib/action_controller/assertions.rb
index e81ebfb893..443449345b 100644
--- a/actionpack/lib/action_controller/assertions.rb
+++ b/actionpack/lib/action_controller/assertions.rb
@@ -108,13 +108,14 @@ module Test #:nodoc:
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: <?>",
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index 56b1752392..38aee0077d 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -124,9 +124,18 @@ 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 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
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
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 8def5556b2..93eded194e 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -134,6 +134,13 @@ class LegacyRouteSetTests < Test::Unit::TestCase
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 @@ class RouteSetTest < Test::Unit::TestCase
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 @@ class RouteSetTest < Test::Unit::TestCase
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