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

Ticket #10818: simplified_route_aliasing.patch

File simplified_route_aliasing.patch, 2.7 kB (added by bscofield, 8 months ago)

patch for map.root only, with docs, code, and test

  • a/actionpack/lib/action_controller/routing.rb

    old new  
    115115  #   root_url   # => 'http://www.example.com/' 
    116116  #   root_path  # => '' 
    117117  # 
     118  # You can also specify an already-defined named route in your map.root call: 
     119  # 
     120  #   # In routes.rb 
     121  #   map.new_session :controller => 'sessions', :action => 'new' 
     122  #   map.root :new_session 
     123  # 
    118124  # Note: when using +with_options+, the route is simply named after the 
    119125  # method you call on the block parameter rather than map. 
    120126  # 
  • a/actionpack/lib/action_controller/routing/route_set.rb

    old new  
    1919 
    2020        # Creates a named route called "root" for matching the root level request. 
    2121        def root(options = {}) 
     22          if options.is_a?(Symbol)  
     23            if source_route = @set.named_routes.routes[options]  
     24              options = source_route.defaults.merge({ :conditions => source_route.conditions })  
     25            end 
     26          end 
    2227          named_route("root", '', options) 
    2328        end 
    2429 
  • a/actionpack/test/controller/routing_test.rb

    old new  
    18081808    Object.send(:remove_const, :PeopleController) 
    18091809  end 
    18101810   
     1811  def test_recognize_with_alias_in_conditions  
     1812    Object.const_set(:PeopleController, Class.new)  
     1813    
     1814    set.draw do |map|  
     1815      map.people "/people", :controller => 'people', :action => "index",  
     1816        :conditions => { :method => :get }  
     1817      map.root   :people 
     1818    end  
     1819 
     1820    request.path = "/people"  
     1821    request.method = :get  
     1822    assert_nothing_raised { set.recognize(request) }  
     1823    assert_equal("people", request.path_parameters[:controller])  
     1824    assert_equal("index", request.path_parameters[:action])  
     1825 
     1826    request.path = "/"  
     1827    request.method = :get  
     1828    assert_nothing_raised { set.recognize(request) }  
     1829    assert_equal("people", request.path_parameters[:controller])  
     1830    assert_equal("index", request.path_parameters[:action])  
     1831  ensure  
     1832    Object.send(:remove_const, :PeopleController)  
     1833  end 
     1834   
    18111835  def test_typo_recognition 
    18121836    Object.const_set(:ArticlesController, Class.new) 
    18131837