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

Changeset 8169

Show
Ignore:
Timestamp:
11/20/07 21:25:25 (1 year ago)
Author:
nzkoz
Message:

Ensure that the routing optimisation code isn't used when additional arguments are passed to the named route. Closes #10209 [bscofield, Koz]

Files:

Legend:

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

    r8094 r8169  
    273273 
    274274    HTTP_METHODS = [:get, :head, :post, :put, :delete] 
     275 
     276    ALLOWED_REQUIREMENTS_FOR_OPTIMISATION = [:controller, :action].to_set 
    275277 
    276278    # The root paths which may contain controller files 
     
    354356        @requirements = {} 
    355357        @conditions = {} 
     358        @optimise = true 
    356359      end 
    357360 
     
    10221025        route.conditions = conditions 
    10231026 
     1027        if !route.significant_keys.include?(:action) && !route.requirements[:action] 
     1028          route.requirements[:action] = "index" 
     1029          route.significant_keys << :action 
     1030        end 
     1031 
    10241032        # Routes cannot use the current string interpolation method 
    10251033        # if there are user-supplied :requirements as the interpolation 
    10261034        # code won't raise RoutingErrors when generating 
    1027         route.optimise = !options.key?(:requirements) 
    1028         if !route.significant_keys.include?(:action) && !route.requirements[:action] 
    1029           route.requirements[:action] = "index" 
    1030           route.significant_keys << :action 
     1035        if options.key?(:requirements) || route.requirements.keys.to_set != Routing::ALLOWED_REQUIREMENTS_FOR_OPTIMISATION 
     1036          route.optimise = false 
    10311037        end 
    10321038 
  • trunk/actionpack/test/controller/routing_test.rb

    r7898 r8169  
    213213      x = setup_for_named_route 
    214214      x.expects(:url_for).never 
    215       # x.send(:users_url) 
     215      x.send(:users_url) 
    216216      x.send(:users_path) 
    217       # x.send(:user_url, 2, :foo=>"bar") 
     217      x.send(:user_url, 2, :foo=>"bar") 
    218218      x.send(:user_path, 3, :bar=>"foo") 
    219219    end 
     220     
     221    def test_optimized_named_route_with_host  
     222        rs.add_named_route :pages, 'pages', :controller => 'content', :action => 'show_page', :host => 'foo.com'  
     223        x = setup_for_named_route  
     224        x.expects(:url_for).with(:host => 'foo.com', :only_path => false, :controller => 'content', :action => 'show_page', :use_route => :pages).once 
     225      x.send(:pages_url) 
     226    end 
     227     
    220228  end 
    221229