Permalink
Browse files

Merge pull request #3337 from htanata/fix_rake_routes_for_controller_…

…only_route

Remove trailing "#" on rake routes for controller only routes
  • Loading branch information...
2 parents e22a4c6 + 010622b commit e886f97669d5aa072af7bb625f5e16635e187124 @josevalim josevalim committed Oct 29, 2011
@@ -10,20 +10,21 @@ def format all_routes, filter = nil
end
routes = all_routes.collect do |route|
+ route_reqs = route.requirements
- reqs = route.requirements.dup
rack_app = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
- endpoint = rack_app ? rack_app.inspect : "#{reqs[:controller]}##{reqs[:action]}"
- constraints = reqs.except(:controller, :action)
+ controller = route_reqs[:controller] || ':controller'
+ action = route_reqs[:action] || ':action'
- reqs = endpoint == '#' ? '' : endpoint
+ endpoint = rack_app ? rack_app.inspect : "#{controller}##{action}"
+ constraints = route_reqs.except(:controller, :action)
- unless constraints.empty?
- reqs = reqs.empty? ? constraints.inspect : "#{reqs} #{constraints.inspect}"
- end
+ reqs = endpoint
+ reqs += " #{constraints.inspect}" unless constraints.empty?
verb = route.verb.source.gsub(/[$^]/, '')
+
{:name => route.name.to_s, :verb => verb, :path => route.path.spec.to_s, :reqs => reqs}
end
@@ -49,20 +49,28 @@ def test_inspect_routes_shows_root_route
assert_equal ["root / pages#main"], output
end
+ def test_inspect_routes_shows_dynamic_action_route
+ @set.draw do
+ match 'api/:action' => 'api'
+ end
+ output = @inspector.format @set.routes
+ assert_equal [" /api/:action(.:format) api#:action"], output
+ end
+
def test_inspect_routes_shows_controller_and_action_only_route
@set.draw do
match ':controller/:action'
end
output = @inspector.format @set.routes
- assert_equal [" /:controller/:action(.:format) "], output
+ assert_equal [" /:controller/:action(.:format) :controller#:action"], output
end
def test_inspect_routes_shows_controller_and_action_route_with_constraints
@set.draw do
match ':controller(/:action(/:id))', :id => /\d+/
end
output = @inspector.format @set.routes
- assert_equal [" /:controller(/:action(/:id))(.:format) {:id=>/\\d+/}"], output
+ assert_equal [" /:controller(/:action(/:id))(.:format) :controller#:action {:id=>/\\d+/}"], output
end
def test_rake_routes_shows_route_with_defaults

0 comments on commit e886f97

Please sign in to comment.