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

Changeset 8227

Show
Ignore:
Timestamp:
11/28/07 04:11:37 (10 months ago)
Author:
nzkoz
Message:

Make sure the optimisation code for routes doesn't get used if :host, :anchor or :port are provided in the hash arguments. [pager, Koz] Closes #10292

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r8226 r8227  
    11*SVN* 
     2 
     3* Make sure the optimisation code for routes doesn't get used if :host, :anchor or :port are provided in the hash arguments. [pager, Koz] #10292 
    24 
    35* Added protection from trailing slashes on page caching #10229 [devrieda] 
  • trunk/actionpack/lib/action_controller/routing_optimisation.rb

    r7676 r8227  
    9898      class PositionalArgumentsWithAdditionalParams < PositionalArguments 
    9999        def guard_condition 
    100           "defined?(request) && request && args.size == #{route.segment_keys.size + 1}
     100          "defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)
    101101        end 
    102102 
  • trunk/actionpack/test/controller/routing_test.rb

    r8216 r8227  
    219219    end 
    220220     
    221     def test_optimized_named_route_with_host  
     221    def test_optimised_named_route_with_host  
    222222        rs.add_named_route :pages, 'pages', :controller => 'content', :action => 'show_page', :host => 'foo.com'  
    223223        x = setup_for_named_route  
    224224        x.expects(:url_for).with(:host => 'foo.com', :only_path => false, :controller => 'content', :action => 'show_page', :use_route => :pages).once 
    225225      x.send(:pages_url) 
    226     end 
    227      
     226    end   
    228227  end 
    229228 
     
    937936    def url_for(options) 
    938937      only_path = options.delete(:only_path) 
     938       
     939      port        = options.delete(:port) || 80 
     940      port_string = port == 80 ? '' : ":#{port}" 
     941       
     942      host   = options.delete(:host) || "named.route.test" 
     943      anchor = "##{options.delete(:anchor)}" if options.key?(:anchor) 
     944       
    939945      path = routes.generate(options) 
    940       only_path ? path : "http://named.route.test#{path}" 
     946       
     947      only_path ? "#{path}#{anchor}" : "http://#{host}#{port_string}#{path}#{anchor}" 
    941948    end 
    942949     
     
    15541561  end 
    15551562 
    1556   def test_namd_route_url_method_with_ordered_parameters 
     1563  def test_named_route_url_method_with_anchor 
     1564    controller = setup_named_route_test 
     1565 
     1566    assert_equal "http://named.route.test/people/5#location", controller.send(:show_url, :id => 5, :anchor => 'location') 
     1567    assert_equal "/people/5#location", controller.send(:show_path, :id => 5, :anchor => 'location') 
     1568 
     1569    assert_equal "http://named.route.test/people#location", controller.send(:index_url, :anchor => 'location') 
     1570    assert_equal "/people#location", controller.send(:index_path, :anchor => 'location') 
     1571 
     1572    assert_equal "http://named.route.test/admin/users#location", controller.send(:users_url, :anchor => 'location') 
     1573    assert_equal '/admin/users#location', controller.send(:users_path, :anchor => 'location') 
     1574 
     1575    assert_equal "http://named.route.test/people/go/7/hello/joe/5#location", 
     1576      controller.send(:multi_url, 7, "hello", 5, :anchor => 'location') 
     1577 
     1578    assert_equal "http://named.route.test/people/go/7/hello/joe/5?baz=bar#location", 
     1579      controller.send(:multi_url, 7, "hello", 5, :baz => "bar", :anchor => 'location') 
     1580 
     1581    assert_equal "http://named.route.test/people?baz=bar#location", 
     1582      controller.send(:index_url, :baz => "bar", :anchor => 'location') 
     1583  end 
     1584   
     1585  def test_named_route_url_method_with_port 
     1586    controller = setup_named_route_test 
     1587    assert_equal "http://named.route.test:8080/people/5", controller.send(:show_url, 5, :port=>8080) 
     1588  end 
     1589   
     1590  def test_named_route_url_method_with_host 
     1591    controller = setup_named_route_test 
     1592    assert_equal "http://some.example.com/people/5", controller.send(:show_url, 5, :host=>"some.example.com") 
     1593  end 
     1594   
     1595 
     1596  def test_named_route_url_method_with_ordered_parameters 
    15571597    controller = setup_named_route_test 
    15581598    assert_equal "http://named.route.test/people/go/7/hello/joe/5",