提交 26e7400c 编写于 作者: J José Valim

Fix diagnostics page for routing errors.

上级 283a0876
......@@ -68,9 +68,9 @@
<%= f.text_field :version %>
<% end %>
* Refactor ActionDispatch::ShowExceptions. Controller is responsible for choice to show exceptions. *Sergey Nartimov*
* Refactor ActionDispatch::ShowExceptions. Controller is responsible for choosing to show exceptions when `consider_all_requests_local` is false. *Sergey Nartimov*
It's possible to override +show_detailed_exceptions?+ in controllers to specify which requests should provide debugging information on errors.
It's possible to override `show_detailed_exceptions?` in controllers to specify which requests should provide debugging information on errors.
* Responders now return 204 No Content for API requests without a response body (as in the new scaffold) *José Valim*
......
......@@ -3,11 +3,6 @@ module Rescue
extend ActiveSupport::Concern
include ActiveSupport::Rescuable
included do
config_accessor :consider_all_requests_local
self.consider_all_requests_local = false if consider_all_requests_local.nil?
end
def rescue_with_handler(exception)
if (exception.respond_to?(:original_exception) &&
(orig_exception = exception.original_exception) &&
......@@ -18,14 +13,14 @@ def rescue_with_handler(exception)
end
def show_detailed_exceptions?
consider_all_requests_local || request.local?
request.local?
end
private
def process_action(*args)
super
rescue Exception => exception
request.env['action_dispatch.show_detailed_exceptions'] = show_detailed_exceptions?
request.env['action_dispatch.show_detailed_exceptions'] ||= show_detailed_exceptions?
rescue_with_handler(exception) || raise(exception)
end
end
......
......@@ -21,8 +21,6 @@ class Railtie < Rails::Railtie
paths = app.config.paths
options = app.config.action_controller
options.consider_all_requests_local ||= app.config.consider_all_requests_local
options.assets_dir ||= paths["public"].first
options.javascripts_dir ||= paths["public/javascripts"].first
options.stylesheets_dir ||= paths["public/stylesheets"].first
......
......@@ -5,9 +5,17 @@ class ShowExceptionsController < ActionController::Base
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
before_filter :only => :another_boom do
request.env["action_dispatch.show_detailed_exceptions"] = true
end
def boom
raise 'boom!'
end
def another_boom
raise 'boom!'
end
end
class ShowExceptionsTest < ActionDispatch::IntegrationTest
......@@ -27,9 +35,8 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
end
end
test 'show diagnostics from a remote ip when consider_all_requests_local is true' do
ShowExceptionsController.any_instance.stubs(:consider_all_requests_local).returns(true)
@app = ShowExceptionsController.action(:boom)
test 'show diagnostics from a remote ip when env is already set' do
@app = ShowExceptionsController.action(:another_boom)
self.remote_addr = '208.77.188.166'
get '/'
assert_match(/boom/, body)
......
......@@ -168,6 +168,7 @@ def env_config
"action_dispatch.parameter_filter" => config.filter_parameters,
"action_dispatch.secret_token" => config.secret_token,
"action_dispatch.show_exceptions" => config.action_dispatch.show_exceptions,
"action_dispatch.show_detailed_exceptions" => config.consider_all_requests_local,
"action_dispatch.logger" => Rails.logger,
"action_dispatch.backtrace_cleaner" => Rails.backtrace_cleaner
})
......
......@@ -45,7 +45,7 @@ def call(env)
assert_equal 404, last_response.status
end
test "unspecified route when set action_dispatch.show_exceptions to false" do
test "unspecified route when action_dispatch.show_exceptions is not set raises an exception" do
app.config.action_dispatch.show_exceptions = false
assert_raise(ActionController::RoutingError) do
......@@ -53,11 +53,22 @@ def call(env)
end
end
test "unspecified route when set action_dispatch.show_exceptions to true" do
test "unspecified route when action_dispatch.show_exceptions is set shows 404" do
app.config.action_dispatch.show_exceptions = true
assert_nothing_raised(ActionController::RoutingError) do
get '/foo'
assert_match "The page you were looking for doesn't exist.", last_response.body
end
end
test "unspecified route when action_dispatch.show_exceptions and consider_all_requests_local are set shows diagnostics" do
app.config.action_dispatch.show_exceptions = true
app.config.consider_all_requests_local = true
assert_nothing_raised(ActionController::RoutingError) do
get '/foo'
assert_match "No route matches", last_response.body
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册