aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md4
-rw-r--r--actionpack/lib/action_dispatch/routing/inspector.rb3
-rw-r--r--actionpack/test/dispatch/routing/inspector_test.rb32
3 files changed, 22 insertions, 17 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 19eb098d16..622a31cd45 100644
--- a/actionpack/CHANGELOG.md
+++ b/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:
diff --git a/actionpack/lib/action_dispatch/routing/inspector.rb b/actionpack/lib/action_dispatch/routing/inspector.rb
index cffb814e1e..120bc54333 100644
--- a/actionpack/lib/action_dispatch/routing/inspector.rb
+++ b/actionpack/lib/action_dispatch/routing/inspector.rb
@@ -179,7 +179,8 @@ module ActionDispatch
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]}"
diff --git a/actionpack/test/dispatch/routing/inspector_test.rb b/actionpack/test/dispatch/routing/inspector_test.rb
index 4f97d28d2b..c63c1475a3 100644
--- a/actionpack/test/dispatch/routing/inspector_test.rb
+++ b/actionpack/test/dispatch/routing/inspector_test.rb
@@ -46,8 +46,8 @@ module ActionDispatch
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"
@@ -61,7 +61,7 @@ module ActionDispatch
assert_equal [
"Prefix Verb URI Pattern Controller#Action",
- "cart GET /cart(.:format) cart#show"
+ "cart GET /cart(.:format) cart#show"
], output
end
@@ -72,7 +72,7 @@ module ActionDispatch
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
@@ -101,7 +101,7 @@ module ActionDispatch
assert_equal [
"Prefix Verb URI Pattern Controller#Action",
- "root GET / pages#main"
+ " root GET / pages#main"
], output
end
@@ -112,7 +112,7 @@ module ActionDispatch
assert_equal [
"Prefix Verb URI Pattern Controller#Action",
- " GET /api/:action(.:format) api#:action"
+ " GET /api/:action(.:format) api#:action"
], output
end
@@ -123,7 +123,7 @@ module ActionDispatch
assert_equal [
"Prefix Verb URI Pattern Controller#Action",
- " GET /:controller/:action(.:format) :controller#:action"
+ " GET /:controller/:action(.:format) :controller#:action"
], output
end
@@ -134,7 +134,7 @@ module ActionDispatch
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
@@ -145,7 +145,7 @@ module ActionDispatch
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
@@ -156,7 +156,7 @@ module ActionDispatch
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
@@ -172,7 +172,7 @@ module ActionDispatch
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
@@ -191,7 +191,7 @@ module ActionDispatch
assert_equal [
"Prefix Verb URI Pattern Controller#Action",
- " /foo #{RackApp.name} {:constraint=>( my custom constraint )}"
+ " /foo #{RackApp.name} {:constraint=>( my custom constraint )}"
], output
end
@@ -212,9 +212,9 @@ module ActionDispatch
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
@@ -241,7 +241,7 @@ module ActionDispatch
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