Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 5785

Show
Ignore:
Timestamp:
12/25/06 09:34:01 (2 years ago)
Author:
rick
Message:

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]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/assertions/response_assertions.rb

    r5466 r5785  
    7171              if value.respond_to?(:[]) && value['controller'] 
    7272                if key == :actual && value['controller'].first != '/' && !value['controller'].include?('/') 
    73                   value['controller'] = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.controller_path) 
     73                  new_controller_path = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.controller_path) 
     74                  value['controller'] = new_controller_path if value['controller'] != new_controller_path && ActionController::Routing.possible_controllers.include?(new_controller_path) 
    7475                end 
    7576                value['controller'] = value['controller'][1..-1] if value['controller'].first == '/' # strip leading hash 
     
    7778              url[key] = value 
    7879            end 
    79  
    8080 
    8181            @response_diff = url[:expected].diff(url[:actual]) if url[:actual] 
  • trunk/actionpack/test/controller/action_pack_assertions_test.rb

    r5646 r5785  
    140140      redirect_to :controller => 'user' 
    141141    end 
     142     
     143    def redirect_to_top_level_named_route 
     144      redirect_to top_level_url(:id => "foo") 
     145    end 
    142146  end 
    143147end 
     
    151155ActionPackAssertionsController.template_root = File.dirname(__FILE__) + "/../fixtures/" 
    152156 
    153  
    154157# a test case to exercise the new capabilities TestRequest & TestResponse 
    155158class ActionPackAssertionsControllerTest < Test::Unit::TestCase 
    156159  # let's get this party started 
    157160  def setup 
     161    ActionController::Routing::Routes.reload 
     162    ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module content admin/user)) 
    158163    @controller = ActionPackAssertionsController.new 
    159164    @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new 
     165  end 
     166 
     167  def teardown 
     168    ActionController::Routing::Routes.reload 
    160169  end 
    161170 
     
    295304    end 
    296305  end 
     306   
     307  def test_assert_redirected_to_top_level_named_route_from_nested_controller 
     308    with_routing do |set| 
     309      set.draw do |map| 
     310        map.top_level '/action_pack_assertions/:id', :controller => 'action_pack_assertions', :action => 'index' 
     311        map.connect   ':controller/:action/:id' 
     312      end 
     313      @controller = Admin::InnerModuleController.new 
     314      process :redirect_to_top_level_named_route 
     315      # passes -> assert_redirected_to "http://test.host/action_pack_assertions/foo" 
     316      assert_redirected_to "/action_pack_assertions/foo" 
     317    end 
     318  end 
    297319 
    298320  # test the flash-based assertions with something is in the flash 
  • trunk/actionpack/test/controller/test_test.rb

    r5643 r5785  
    8787    @response   = ActionController::TestResponse.new 
    8888    ActionController::Routing::Routes.reload 
    89     ActionController::Routing.use_controllers! %w(content admin/user
     89    ActionController::Routing.use_controllers! %w(content admin/user test_test/test
    9090  end 
    9191