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

Ticket #883: route_paths_as_arrays.3.patch

File route_paths_as_arrays.3.patch, 3.4 kB (added by Ulysses, 4 years ago)

Third times the charm

  • actionpack/test/controller/routing_tests.rb

    old new  
    329329  def test_path_collection 
    330330    route '*path_info', :controller => 'content', :action => 'fish' 
    331331    verify_recognize'path/with/slashes', 
    332         :controller => 'content', :action => 'fish', :path_info => 'path/with/slashes' 
     332        :controller => 'content', :action => 'fish', :path_info => %w(path with slashes) 
    333333    verify_generate('path/with/slashes', {}, 
    334        {:controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'}, 
     334        {:controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'}, 
    335335        {}) 
    336336  end 
     337  def test_path_collection_with_array 
     338    route '*path_info', :controller => 'content', :action => 'fish' 
     339    verify_recognize'path/with/slashes', 
     340        :controller => 'content', :action => 'fish', :path_info => %w(path with slashes) 
     341    verify_generate('path/with/slashes', {}, 
     342        {:controller => 'content', :action => 'fish', :path_info => %w(path with slashes)}, 
     343        {}) 
     344  end 
     345 
     346 
    337347   
    338348  def test_special_characters 
    339349    route ':id', :controller => 'content', :action => 'fish' 
  • actionpack/lib/action_controller/routing.rb

    old new  
    4747         
    4848        used_names = @requirements.inject({}) {|hash, (k, v)| hash[k] = true; hash} # Mark requirements as used so they don't get put in the query params 
    4949        components = @items.collect do |item| 
     50 
    5051          if item.kind_of? Symbol 
    5152            collection = false 
    5253 
     
    6465            if value.nil? || item == :controller 
    6566              value 
    6667            elsif collection 
    67                     Routing.extract_parameter_value(value).gsub(/%2F/, "/") 
     68              if value.kind_of?(Array) 
     69                value = value.collect {|v| Routing.extract_parameter_value(v)}.join('/') 
     70              else 
     71                value = Routing.extract_parameter_value(value).gsub(/%2F/, "/") 
     72              end 
     73              value 
    6874            else 
    6975              Routing.extract_parameter_value(value) 
    7076            end 
     
    113119            options[:controller] = controller_class.controller_path 
    114120            return nil, requirements_for(:controller) unless passes_requirements?(:controller, options[:controller]) 
    115121          elsif /^\*/ =~ item.to_s 
    116             value = components.join("/") || @defaults[item] 
     122            value = components.empty? ? @defaults[item].clone : components.clone 
     123            value.collect! {|c| CGI.unescape c} 
    117124            components = [] 
    118             options[item.to_s.sub(/^\*/,"").intern] = value.nil? ? value : CGI.unescape(value) 
     125            def value.to_s() self.join('/') end 
     126            options[item.to_s.sub(/^\*/,"").intern] = value 
    119127          elsif item.kind_of? Symbol 
    120128            value = components.shift || @defaults[item] 
    121129            return nil, requirements_for(item) unless passes_requirements?(item, value)