aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-11-30 09:52:52 +0100
committerJosé Valim <jose.valim@gmail.com>2011-11-30 09:53:09 +0100
commit38ab982cfff98570b5f12933cff489364845789c (patch)
tree20c563f1e1447234a1dfdb2e385c1ae06bd328ed /activesupport
parenta6ee246e5cea1c1a71631c6bef3740a4bf4eb250 (diff)
downloadrails-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 'activesupport')
-rw-r--r--activesupport/lib/active_support/callbacks.rb18
-rw-r--r--activesupport/test/callbacks_test.rb12
2 files changed, 25 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index ea37355fc1..11069301f1 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -81,6 +81,14 @@ module ActiveSupport
send("_run_#{kind}_callbacks", *args, &block)
end
+ private
+
+ # A hook invoked everytime a before callback is halted.
+ # This can be overriden in AS::Callback implementors in order
+ # to provide better debugging/logging.
+ def halted_callback_hook(filter)
+ end
+
class Callback #:nodoc:#
@@_callback_sequence = 0
@@ -173,12 +181,14 @@ module ActiveSupport
# end
<<-RUBY_EVAL
if !halted && #{@compiled_options}
- # This double assignment is to prevent warnings in 1.9.3. I would
- # remove the `result` variable, but apparently some other
- # generated code is depending on this variable being set sometimes
- # and sometimes not.
+ # This double assignment is to prevent warnings in 1.9.3 as
+ # the `result` variable is not always used except if the
+ # terminator code refers to it.
result = result = #{@filter}
halted = (#{chain.config[:terminator]})
+ if halted
+ halted_callback_hook(#{@raw_filter.inspect.inspect})
+ end
end
RUBY_EVAL
when :around
diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb
index 2b4adda4d1..e723121bb4 100644
--- a/activesupport/test/callbacks_test.rb
+++ b/activesupport/test/callbacks_test.rb
@@ -461,7 +461,7 @@ module CallbacksTest
set_callback :save, :after, :third
- attr_reader :history, :saved
+ attr_reader :history, :saved, :halted
def initialize
@history = []
end
@@ -490,6 +490,10 @@ module CallbacksTest
@saved = true
end
end
+
+ def halted_callback_hook(filter)
+ @halted = filter
+ end
end
class CallbackObject
@@ -595,6 +599,12 @@ module CallbacksTest
assert_equal ["first", "second", "third", "second", "first"], terminator.history
end
+ def test_termination_invokes_hook
+ terminator = CallbackTerminator.new
+ terminator.save
+ assert_equal ":second", terminator.halted
+ end
+
def test_block_never_called_if_terminated
obj = CallbackTerminator.new
obj.save