diff options
author | José Valim <jose.valim@gmail.com> | 2011-11-30 09:52:52 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-11-30 09:53:09 +0100 |
commit | 38ab982cfff98570b5f12933cff489364845789c (patch) | |
tree | 20c563f1e1447234a1dfdb2e385c1ae06bd328ed /actionpack | |
parent | a6ee246e5cea1c1a71631c6bef3740a4bf4eb250 (diff) | |
download | rails-38ab982cfff98570b5f12933cff489364845789c.tar.gz rails-38ab982cfff98570b5f12933cff489364845789c.tar.bz2 rails-38ab982cfff98570b5f12933cff489364845789c.zip |
Log 'Filter chain halted as CALLBACKNAME rendered or redirected' every time a before callback halts.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/log_subscriber.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/instrumentation.rb | 7 | ||||
-rw-r--r-- | actionpack/test/controller/log_subscriber_test.rb | 13 |
4 files changed, 24 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 314aa7181c..b091d12d2c 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 3.2.0 (unreleased) ## +* Log "Filter chain halted as CALLBACKNAME rendered or redirected" every time a before callback halts. *José Valim* + * You can provide a namespace for your form to ensure uniqueness of id attributes on form elements. The namespace attribute will be prefixed with underscore on the generate HTML id. *Vasiliy Ermolovich* diff --git a/actionpack/lib/action_controller/log_subscriber.rb b/actionpack/lib/action_controller/log_subscriber.rb index 35e29398e6..8666ecc9c8 100644 --- a/actionpack/lib/action_controller/log_subscriber.rb +++ b/actionpack/lib/action_controller/log_subscriber.rb @@ -29,6 +29,10 @@ module ActionController info(message) end + def halted_callback(event) + info "Filter chain halted as #{event.payload[:filter]} rendered or redirected" + end + def send_file(event) message = "Sent file %s" message << " (%.1fms)" diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb index 777a0ab343..640ebf5f00 100644 --- a/actionpack/lib/action_controller/metal/instrumentation.rb +++ b/actionpack/lib/action_controller/metal/instrumentation.rb @@ -64,7 +64,12 @@ module ActionController end end - protected + private + + # A hook invoked everytime a before callback is halted. + def halted_callback_hook(filter) + ActiveSupport::Notifications.instrument("halted_callback.action_controller", :filter => filter) + end # A hook which allows you to clean up any time taken into account in # views wrongly, like database querying time. diff --git a/actionpack/test/controller/log_subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb index ccdfcb0b2c..700fd788fa 100644 --- a/actionpack/test/controller/log_subscriber_test.rb +++ b/actionpack/test/controller/log_subscriber_test.rb @@ -13,6 +13,11 @@ module Another head :status => 406 end + before_filter :redirector, :only => :never_executed + + def never_executed + end + def show render :nothing => true end @@ -49,7 +54,6 @@ module Another def with_rescued_exception raise SpecialException end - end end @@ -86,6 +90,13 @@ class ACLogSubscriberTest < ActionController::TestCase assert_equal "Processing by Another::LogSubscribersController#show as HTML", logs.first end + def test_halted_callback + get :never_executed + wait + assert_equal 4, logs.size + assert_equal "Filter chain halted as :redirector rendered or redirected", logs.third + end + def test_process_action get :show wait |