Skip to content

Commit

Permalink
Fix for routes task
Browse files Browse the repository at this point in the history
This commit fixes formatting issue for `rake routes` task, when a section is shorter than a header.
  • Loading branch information
sbagdat committed Nov 21, 2013
1 parent 64b9e93 commit 6701b4c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,3 +1,7 @@
* Fix formatting for `rake routes` when a section is shorter than a header

*Sıtkı Bağdat*

* Take a hash with options inside array in #url_for

Example:
Expand Down
3 changes: 2 additions & 1 deletion actionpack/lib/action_dispatch/routing/inspector.rb
Expand Up @@ -179,7 +179,8 @@ def no_routes

private
def draw_section(routes)
name_width, verb_width, path_width = widths(routes)
header_lengths = ['Prefix', 'Verb', 'URI Pattern'].map(&:length)
name_width, verb_width, path_width = widths(routes).zip(header_lengths).map(&:max)

routes.map do |r|
"#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
Expand Down
32 changes: 16 additions & 16 deletions actionpack/test/dispatch/routing/inspector_test.rb
Expand Up @@ -46,8 +46,8 @@ def self.inspect

assert_equal [
" Prefix Verb URI Pattern Controller#Action",
"custom_assets GET /custom/assets(.:format) custom_assets#show",
" blog /blog Blog::Engine",
"custom_assets GET /custom/assets(.:format) custom_assets#show",
" blog /blog Blog::Engine",
"",
"Routes for Blog::Engine:",
"cart GET /cart(.:format) cart#show"
Expand All @@ -61,7 +61,7 @@ def test_cart_inspect

assert_equal [
"Prefix Verb URI Pattern Controller#Action",
"cart GET /cart(.:format) cart#show"
"cart GET /cart(.:format) cart#show"
], output
end

Expand All @@ -72,7 +72,7 @@ def test_inspect_shows_custom_assets

assert_equal [
" Prefix Verb URI Pattern Controller#Action",
"custom_assets GET /custom/assets(.:format) custom_assets#show"
"custom_assets GET /custom/assets(.:format) custom_assets#show"
], output
end

Expand Down Expand Up @@ -101,7 +101,7 @@ def test_inspect_routes_shows_root_route

assert_equal [
"Prefix Verb URI Pattern Controller#Action",
"root GET / pages#main"
" root GET / pages#main"
], output
end

Expand All @@ -112,7 +112,7 @@ def test_inspect_routes_shows_dynamic_action_route

assert_equal [
"Prefix Verb URI Pattern Controller#Action",
" GET /api/:action(.:format) api#:action"
" GET /api/:action(.:format) api#:action"
], output
end

Expand All @@ -123,7 +123,7 @@ def test_inspect_routes_shows_controller_and_action_only_route

assert_equal [
"Prefix Verb URI Pattern Controller#Action",
" GET /:controller/:action(.:format) :controller#:action"
" GET /:controller/:action(.:format) :controller#:action"
], output
end

Expand All @@ -134,7 +134,7 @@ def test_inspect_routes_shows_controller_and_action_route_with_constraints

assert_equal [
"Prefix Verb URI Pattern Controller#Action",
" GET /:controller(/:action(/:id))(.:format) :controller#:action {:id=>/\\d+/}"
" GET /:controller(/:action(/:id))(.:format) :controller#:action {:id=>/\\d+/}"
], output
end

Expand All @@ -145,7 +145,7 @@ def test_rake_routes_shows_route_with_defaults

assert_equal [
"Prefix Verb URI Pattern Controller#Action",
%Q[ GET /photos/:id(.:format) photos#show {:format=>"jpg"}]
%Q[ GET /photos/:id(.:format) photos#show {:format=>"jpg"}]
], output
end

Expand All @@ -156,7 +156,7 @@ def test_rake_routes_shows_route_with_constraints

assert_equal [
"Prefix Verb URI Pattern Controller#Action",
" GET /photos/:id(.:format) photos#show {:id=>/[A-Z]\\d{5}/}"
" GET /photos/:id(.:format) photos#show {:id=>/[A-Z]\\d{5}/}"
], output
end

Expand All @@ -172,7 +172,7 @@ def test_rake_routes_shows_route_with_rack_app

assert_equal [
"Prefix Verb URI Pattern Controller#Action",
" GET /foo/:id(.:format) #{RackApp.name} {:id=>/[A-Z]\\d{5}/}"
" GET /foo/:id(.:format) #{RackApp.name} {:id=>/[A-Z]\\d{5}/}"
], output
end

Expand All @@ -191,7 +191,7 @@ def inspect

assert_equal [
"Prefix Verb URI Pattern Controller#Action",
" /foo #{RackApp.name} {:constraint=>( my custom constraint )}"
" /foo #{RackApp.name} {:constraint=>( my custom constraint )}"
], output
end

Expand All @@ -212,9 +212,9 @@ def test_redirect

assert_equal [
"Prefix Verb URI Pattern Controller#Action",
" foo GET /foo(.:format) redirect(301, /foo/bar) {:subdomain=>\"admin\"}",
" bar GET /bar(.:format) redirect(307, path: /foo/bar)",
"foobar GET /foobar(.:format) redirect(301)"
" foo GET /foo(.:format) redirect(301, /foo/bar) {:subdomain=>\"admin\"}",
" bar GET /bar(.:format) redirect(307, path: /foo/bar)",
"foobar GET /foobar(.:format) redirect(301)"
], output
end

Expand All @@ -241,7 +241,7 @@ def test_regression_route_with_controller_regexp
end

assert_equal ["Prefix Verb URI Pattern Controller#Action",
" GET /:controller(/:action) (?-mix:api\\/[^\\/]+)#:action"], output
" GET /:controller(/:action) (?-mix:api\\/[^\\/]+)#:action"], output
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions railties/test/application/rake_test.rb
Expand Up @@ -111,7 +111,7 @@ def test_rake_routes_calls_the_route_inspector
RUBY

output = Dir.chdir(app_path){ `rake routes` }
assert_equal "Prefix Verb URI Pattern Controller#Action\ncart GET /cart(.:format) cart#show\n", output
assert_equal "Prefix Verb URI Pattern Controller#Action\ncart GET /cart(.:format) cart#show\n", output
end

def test_rake_routes_with_controller_environment
Expand All @@ -124,7 +124,7 @@ def test_rake_routes_with_controller_environment

ENV['CONTROLLER'] = 'cart'
output = Dir.chdir(app_path){ `rake routes` }
assert_equal "Prefix Verb URI Pattern Controller#Action\ncart GET /cart(.:format) cart#show\n", output
assert_equal "Prefix Verb URI Pattern Controller#Action\ncart GET /cart(.:format) cart#show\n", output
end

def test_rake_routes_displays_message_when_no_routes_are_defined
Expand Down

0 comments on commit 6701b4c

Please sign in to comment.