Permalink
Browse files

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)
  • Loading branch information...
lukaszx0 committed May 18, 2012
1 parent 61fc10d commit 5f7bfb77786ab02db213f9563c199fc5b7f53f3e
@@ -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

0 comments on commit 5f7bfb7

Please sign in to comment.