Skip to content

Commit

Permalink
Always use ActionDispatch::ShowExceptions middleware [#6462 state:res…
Browse files Browse the repository at this point in the history
…olved]

This will make sure the application will raise `ActionController::RoutingError` in case "X-Cascade: pass" header was set, usually when there's no route match.
  • Loading branch information
sikachu authored and tenderlove committed Feb 25, 2011
1 parent 439a745 commit 515ea95
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion railties/lib/rails/application.rb
Expand Up @@ -157,7 +157,7 @@ def default_middleware_stack
middleware.use ::Rack::Lock unless config.allow_concurrency middleware.use ::Rack::Lock unless config.allow_concurrency
middleware.use ::Rack::Runtime middleware.use ::Rack::Runtime
middleware.use ::Rails::Rack::Logger middleware.use ::Rails::Rack::Logger
middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local if config.action_dispatch.show_exceptions middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local
middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies
middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header
middleware.use ::ActionDispatch::Reloader unless config.cache_classes middleware.use ::ActionDispatch::Reloader unless config.cache_classes
Expand Down
37 changes: 37 additions & 0 deletions railties/test/application/middleware/show_exceptions_test.rb
@@ -0,0 +1,37 @@
require 'isolation/abstract_unit'

module ApplicationTests
class ShowExceptionsTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation

def setup
build_app
boot_rails
FileUtils.rm_rf "#{app_path}/config/environments"
end

def app
@app ||= Rails.application
end

test "unspecified route when set action_dispatch.show_exceptions to false" do
make_basic_app do |app|
app.config.action_dispatch.show_exceptions = false
end

assert_raise(ActionController::RoutingError) do
get '/foo'
end
end

test "unspecified route when set action_dispatch.show_exceptions to true" do
make_basic_app do |app|
app.config.action_dispatch.show_exceptions = true
end

assert_nothing_raised(ActionController::RoutingError) do
get '/foo'
end
end
end
end
4 changes: 2 additions & 2 deletions railties/test/application/middleware_test.rb
Expand Up @@ -78,10 +78,10 @@ def app
assert !middleware.include?("ActionDispatch::Static") assert !middleware.include?("ActionDispatch::Static")
end end


test "removes show exceptions if action_dispatch.show_exceptions is disabled" do test "includes show exceptions even action_dispatch.show_exceptions is disabled" do
add_to_config "config.action_dispatch.show_exceptions = false" add_to_config "config.action_dispatch.show_exceptions = false"
boot! boot!
assert !middleware.include?("ActionDispatch::ShowExceptions") assert middleware.include?("ActionDispatch::ShowExceptions")
end end


test "removes ActionDispatch::Reloader if cache_classes is true" do test "removes ActionDispatch::Reloader if cache_classes is true" do
Expand Down

0 comments on commit 515ea95

Please sign in to comment.