public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fix assert_redirected_to for nested controllers and named routes

[#308 state:resolved]

Signed-off-by: Michael Koziarski <michael@koziarski.com>
dasil003 (author)
Mon Jun 02 15:57:35 -0700 2008
NZKoz (committer)
Tue Jun 03 16:08:58 -0700 2008
commit  025515b234d8380f195e3de3818d076302605b12
tree    ea615e7182e18f01443175a3c32797bb7e24636e
parent  e3c26e9926948587efcc8d31c729395093407df6
...
97
98
99
100
 
101
102
103
...
97
98
99
 
100
101
102
103
0
@@ -97,7 +97,7 @@ module ActionController
0
                 value['controller'] = value['controller'].to_s
0
                 if key == :actual && value['controller'].first != '/' && !value['controller'].include?('/')
0
                   new_controller_path = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.controller_path)
0
-                  value['controller'] = new_controller_path if value['controller'] != new_controller_path && ActionController::Routing.possible_controllers.include?(new_controller_path)
0
+                  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)
0
                 end
0
                 value['controller'] = value['controller'][1..-1] if value['controller'].first == '/' # strip leading hash
0
               end
...
137
138
139
 
 
 
140
141
142
...
174
175
176
177
 
178
179
180
...
268
269
270
271
 
272
273
274
...
277
278
279
280
 
281
282
283
284
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
286
287
...
137
138
139
140
141
142
143
144
145
...
177
178
179
 
180
181
182
183
...
271
272
273
 
274
275
276
277
...
280
281
282
 
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
0
@@ -137,6 +137,9 @@ class AssertResponseWithUnexpectedErrorController < ActionController::Base
0
   end
0
 end
0
 
0
+class UserController < ActionController::Base
0
+end
0
+
0
 module Admin
0
   class InnerModuleController < ActionController::Base
0
     def index
0
@@ -174,7 +177,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
0
   # let's get this party started
0
   def setup
0
     ActionController::Routing::Routes.reload
0
-    ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module content admin/user))
0
+    ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module user content admin/user))
0
     @controller = ActionPackAssertionsController.new
0
     @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
0
   end
0
@@ -268,7 +271,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
0
       assert_redirected_to admin_inner_module_path
0
     end
0
   end
0
-  
0
+
0
   def test_assert_redirected_to_top_level_named_route_from_nested_controller
0
     with_routing do |set|
0
       set.draw do |map|
0
@@ -277,11 +280,25 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
0
       end
0
       @controller = Admin::InnerModuleController.new
0
       process :redirect_to_top_level_named_route
0
-      # passes -> assert_redirected_to "http://test.host/action_pack_assertions/foo"
0
+      # assert_redirected_to "http://test.host/action_pack_assertions/foo" would pass because of exact match early return
0
       assert_redirected_to "/action_pack_assertions/foo"
0
     end
0
   end
0
 
0
+  def test_assert_redirected_to_top_level_named_route_with_same_controller_name_in_both_namespaces
0
+    with_routing do |set|
0
+      set.draw do |map|
0
+        # this controller exists in the admin namespace as well which is the only difference from previous test
0
+        map.top_level '/user/:id', :controller => 'user', :action => 'index'
0
+        map.connect   ':controller/:action/:id'
0
+      end
0
+      @controller = Admin::InnerModuleController.new
0
+      process :redirect_to_top_level_named_route
0
+      # assert_redirected_to top_level_url('foo') would pass because of exact match early return
0
+      assert_redirected_to top_level_path('foo')
0
+    end
0
+  end
0
+
0
   # -- standard request/response object testing --------------------------------
0
 
0
   # make sure that the template objects exist

Comments