Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
dhh committed Aug 5, 2006
1 parent 01e389c commit 5130fc8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
7 changes: 4 additions & 3 deletions actionpack/lib/action_controller/resources.rb
Expand Up @@ -143,9 +143,10 @@ def map_member_actions(map, resource)
end

map.connect(resource.member_path, route_options.merge(:action => primary)) unless primary.blank?
map.named_route("#{resource.name_prefix}#{resource.singular}", resource.member_path, :action => "show", :conditions => { :method => :get })
map.named_route("formatted_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}.:format", :action => "show", :conditions => { :method => :get })
end

map.named_route("#{resource.name_prefix}#{resource.singular}", resource.member_path, :action => "show", :conditions => { :method => :get })
map.named_route("formatted_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}.:format", :action => "show", :conditions => { :method => :get })
end

def requirements_for(method)
Expand All @@ -154,4 +155,4 @@ def requirements_for(method)
end
end

ActionController::Routing::RouteSet::Mapper.send :include, ActionController::Resources
ActionController::Routing::RouteSet::Mapper.send :include, ActionController::Resources
22 changes: 22 additions & 0 deletions actionpack/test/controller/resources_test.rb
Expand Up @@ -133,6 +133,18 @@ def test_nested_restful_routes
:options => { :thread_id => '1', :message_id => '2' }
end
end

def test_restful_routes_dont_generate_duplicates
with_restful_routing :messages do
routes = ActionController::Routing::Routes.routes
routes.each do |route|
routes.each do |r|
next if route === r # skip the comparison instance
assert distinct_routes?(route, r), "Duplicate Route: #{route}"
end
end
end
end

protected
def with_restful_routing(*args)
Expand Down Expand Up @@ -212,4 +224,14 @@ def assert_resource_methods(expected, resource, action_method, method)
"#{method} not in #{action_method} methods: #{resource.send("#{action_method}_methods")[method].inspect}"
end
end

def distinct_routes? (r1, r2)
if r1.conditions == r2.conditions and r1.requirements == r2.requirements then
if r1.segments.collect(&:to_s) == r2.segments.collect(&:to_s) then
return false
end
end
true
end

end

0 comments on commit 5130fc8

Please sign in to comment.