提交 81867540 编写于 作者: A Andrew White

Merge pull request #6461 from schneems/schneems/sextant-routes

View your Routes without waiting on Rake
## Rails 4.0.0 (unreleased) ##
* Add `/rails/info/routes` path, displays same information as `rake routes` *Richard Schneeman & Andrew White*
* Improved `rake routes` output for redirects *Łukasz Strzałkowski & Andrew White*
* Load all environments available in `config.paths["config/environments"]`. *Piotr Sarnacki*
......
......@@ -23,6 +23,8 @@ module Finisher
if Rails.env.development?
app.routes.append do
get '/rails/info/properties' => "rails/info#properties"
get '/rails/info/routes' => "rails/info#routes"
get '/rails/info' => "rails/info#index"
end
end
end
......
......@@ -51,7 +51,7 @@ def action
end
def internal?
path =~ %r{/rails/info/properties|^#{Rails.application.config.assets.prefix}}
path =~ %r{/rails/info.*|^#{Rails.application.config.assets.prefix}}
end
def engine?
......
require 'rails/application/route_inspector'
class Rails::InfoController < ActionController::Base
self.view_paths = File.join(File.dirname(__FILE__), 'templates')
layout 'application'
before_filter :require_local!
def index
redirect_to '/rails/info/routes'
end
def properties
if consider_all_requests_local? || request.local?
render :inline => Rails::Info.to_html
else
render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => :forbidden
end
@info = Rails::Info.to_html
end
def routes
inspector = Rails::Application::RouteInspector.new
@info = inspector.format(_routes.routes).join("\n")
end
protected
def consider_all_requests_local?
Rails.application.config.consider_all_requests_local
def require_local!
unless local_request?
render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => :forbidden
end
end
def local_request?
Rails.application.config.consider_all_requests_local || request.local?
end
end
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Routes</title>
<style>
body { background-color: #fff; color: #333; }
body, p, ol, ul, td {
font-family: helvetica, verdana, arial, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
white-space: pre-wrap;
}
a { color: #000; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }
</style>
</head>
<body>
<h2>Your App: <%= link_to 'properties', '/rails/info/properties' %> | <%= link_to 'routes', '/rails/info/routes' %></h2>
<%= yield %>
</body>
</html>
<%= @info.html_safe %>
\ No newline at end of file
<h2>
Routes
</h2>
<p>
Routes match in priority from top to bottom
</p>
<p><pre><%= @info %></pre></p>
\ No newline at end of file
......@@ -164,5 +164,14 @@ def test_redirect
assert_equal " bar GET /bar(.:format) redirect(307, path: /foo/bar)", output[1]
assert_equal "foobar GET /foobar(.:format) redirect(301)", output[2]
end
def test_presenter
output = draw do
get "/foo" => redirect("/foo/bar"), :constraints => { :subdomain => "admin" }
get "/bar" => redirect(path: "/foo/bar", status: 307)
get "/foobar" => redirect{ "/foo/bar" }
end
assert_equal output.join("\n"), Rails::Application::RoutePresenter.display_routes(@set.routes)
end
end
end
......@@ -15,12 +15,24 @@ def teardown
teardown_app
end
test "rails/info/routes in development" do
app("development")
get "/rails/info/routes"
assert_equal 200, last_response.status
end
test "rails/info/properties in development" do
app("development")
get "/rails/info/properties"
assert_equal 200, last_response.status
end
test "rails/info/routes in production" do
app("production")
get "/rails/info/routes"
assert_equal 404, last_response.status
end
test "rails/info/properties in production" do
app("production")
get "/rails/info/properties"
......
......@@ -12,29 +12,28 @@ class InfoControllerTest < ActionController::TestCase
def setup
Rails.application.routes.draw do
get '/rails/info/properties' => "rails/info#properties"
get '/rails/info/routes' => "rails/info#routes"
end
@request.stubs(:local? => true)
@controller.stubs(:consider_all_requests_local? => false)
@controller.stubs(:local_request? => true)
@routes = Rails.application.routes
Rails::InfoController.send(:include, @routes.url_helpers)
end
test "info controller does not allow remote requests" do
@request.stubs(:local? => false)
@controller.stubs(:local_request? => false)
get :properties
assert_response :forbidden
end
test "info controller renders an error message when request was forbidden" do
@request.stubs(:local? => false)
@controller.stubs(:local_request? => false)
get :properties
assert_select 'p'
end
test "info controller allows requests when all requests are considered local" do
@request.stubs(:local? => false)
@controller.stubs(:consider_all_requests_local? => true)
@controller.stubs(:local_request? => true)
get :properties
assert_response :success
end
......@@ -48,4 +47,10 @@ def setup
get :properties
assert_select 'table'
end
test "info controller renders with routes" do
get :routes
assert_select 'pre'
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册