Browse files

Ensure that status codes are logged properly

Needed to move AC::Metal::Instrumentation before AM::Metal::Rescue
so that status codes rendered from rescue_from blocks are logged
properly.
  • Loading branch information...
1 parent 9a4d2b2 commit 5e64538435e34b67537649ba677bfac441fa70d8 @jstorimer jstorimer committed Jul 18, 2011
Showing with 26 additions and 6 deletions.
  1. +5 −5 actionpack/lib/action_controller/base.rb
  2. +21 −1 actionpack/test/controller/log_subscriber_test.rb
View
10 actionpack/lib/action_controller/base.rb
@@ -204,16 +204,16 @@ def self.without_modules(*modules)
HttpAuthentication::Digest::ControllerMethods,
HttpAuthentication::Token::ControllerMethods,
- # Add instrumentations hooks at the bottom, to ensure they instrument
- # all the methods properly.
- Instrumentation,
-
# Before callbacks should also be executed the earliest as possible, so
# also include them at the bottom.
AbstractController::Callbacks,
# The same with rescue, append it at the end to wrap as much as possible.
- Rescue
+ Rescue,
+
+ # Add instrumentations hooks at the bottom, to ensure they instrument
+ # all the methods properly.
+ Instrumentation
]
MODULES.each do |mod|
View
22 actionpack/test/controller/log_subscriber_test.rb
@@ -4,6 +4,14 @@
module Another
class LogSubscribersController < ActionController::Base
+
+ class SpecialException < Exception
+ end
+
+ rescue_from SpecialException do
+ head :status => 406
+ end
+
def show
render :nothing => true
end
@@ -36,7 +44,11 @@ def with_page_cache
def with_exception
raise Exception
end
-
+
+ def with_rescued_exception
+ raise SpecialException
+ end
+
end
end
@@ -181,6 +193,14 @@ def test_process_action_with_exception_includes_http_status_code
assert_match(/Completed 500/, logs.last)
end
+ def test_process_action_with_rescued_exception_includes_http_status_code
+ get :with_rescued_exception
+ wait
+
+ assert_equal 2, logs.size
+ assert_match(/Completed 406/, logs.last)
+ end
+
def logs
@logs ||= @logger.logged(:info)
end

0 comments on commit 5e64538

Please sign in to comment.