提交 5f7bfb77 编写于 作者: Ł Łukasz Strzałkowski

Fix inspecting route redirections, closes #6369

This commit fixes route inspection in `rake routes`

Before:

  foo  /foo(.:format) :controller#:action"

After:

  foo  /foo(.:format)  Redirect (301)
上级 61fc10d2
......@@ -35,6 +35,10 @@ def call(env)
def path(params, request)
block.call params, request
end
def inspect
"Redirect (#{status})"
end
end
class OptionRedirect < Redirect # :nodoc:
......
......@@ -16,7 +16,7 @@ def rack_app(app = self.app)
class_name = app.class.name.to_s
if class_name == "ActionDispatch::Routing::Mapper::Constraints"
rack_app(app.app)
elsif class_name !~ /^ActionDispatch::Routing/
elsif class_name == "ActionDispatch::Routing::Redirect" || class_name !~ /^ActionDispatch::Routing/
app
end
end
......@@ -67,7 +67,7 @@ def initialize
@engines = Hash.new
end
def format all_routes, filter = nil
def format(all_routes, filter = nil)
if filter
all_routes = all_routes.select{ |route| route.defaults[:controller] == filter }
end
......
......@@ -152,5 +152,14 @@ def test_rake_routes_dont_show_app_mounted_in_assets_prefix
assert_no_match(/RackApp/, output.first)
assert_no_match(/\/sprockets/, output.first)
end
def test_redirect
output = draw do
match '/foo' => redirect("/bar")
match '/foo2' => redirect("/bar", status: 307)
end
assert_equal " foo /foo(.:format) Redirect (301)", output[0]
assert_equal "foo2 /foo2(.:format) Redirect (307)", output[1]
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册