Skip to content
This repository
Browse code

Remove duplicate routes from mapped resources (closes #5712) [eigento…

…ne@gmail.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4669 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 5130fc84c602001d31454a5631ee7b354d197663 1 parent 01e389c
David Heinemeier Hansson dhh authored
7 actionpack/lib/action_controller/resources.rb
@@ -143,9 +143,10 @@ def map_member_actions(map, resource)
143 143 end
144 144
145 145 map.connect(resource.member_path, route_options.merge(:action => primary)) unless primary.blank?
146   - map.named_route("#{resource.name_prefix}#{resource.singular}", resource.member_path, :action => "show", :conditions => { :method => :get })
147   - map.named_route("formatted_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}.:format", :action => "show", :conditions => { :method => :get })
148 146 end
  147 +
  148 + map.named_route("#{resource.name_prefix}#{resource.singular}", resource.member_path, :action => "show", :conditions => { :method => :get })
  149 + map.named_route("formatted_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}.:format", :action => "show", :conditions => { :method => :get })
149 150 end
150 151
151 152 def requirements_for(method)
@@ -154,4 +155,4 @@ def requirements_for(method)
154 155 end
155 156 end
156 157
157   -ActionController::Routing::RouteSet::Mapper.send :include, ActionController::Resources
  158 +ActionController::Routing::RouteSet::Mapper.send :include, ActionController::Resources
22 actionpack/test/controller/resources_test.rb
@@ -133,6 +133,18 @@ def test_nested_restful_routes
133 133 :options => { :thread_id => '1', :message_id => '2' }
134 134 end
135 135 end
  136 +
  137 + def test_restful_routes_dont_generate_duplicates
  138 + with_restful_routing :messages do
  139 + routes = ActionController::Routing::Routes.routes
  140 + routes.each do |route|
  141 + routes.each do |r|
  142 + next if route === r # skip the comparison instance
  143 + assert distinct_routes?(route, r), "Duplicate Route: #{route}"
  144 + end
  145 + end
  146 + end
  147 + end
136 148
137 149 protected
138 150 def with_restful_routing(*args)
@@ -212,4 +224,14 @@ def assert_resource_methods(expected, resource, action_method, method)
212 224 "#{method} not in #{action_method} methods: #{resource.send("#{action_method}_methods")[method].inspect}"
213 225 end
214 226 end
  227 +
  228 + def distinct_routes? (r1, r2)
  229 + if r1.conditions == r2.conditions and r1.requirements == r2.requirements then
  230 + if r1.segments.collect(&:to_s) == r2.segments.collect(&:to_s) then
  231 + return false
  232 + end
  233 + end
  234 + true
  235 + end
  236 +
215 237 end

0 comments on commit 5130fc8

Please sign in to comment.
Something went wrong with that request. Please try again.