Permalink
Browse files

Don't run the action if callbacks are halted.

  In AbstractController, this means that response_body is not empty
  • Loading branch information...
1 parent 34caf4f commit c1d120a71e74aa3ccab6dc28a5406b87a51a69c1 Yehuda Katz + Carl Lerche committed May 11, 2009
@@ -2,7 +2,7 @@ module AbstractController
module Callbacks
setup do
include ActiveSupport::NewCallbacks
- define_callbacks :process_action
+ define_callbacks :process_action, "response_body"
end
def process_action
@@ -316,7 +316,7 @@ def compile(key = nil, options = {})
each do |callback|
method << callback.start(key, options)
end
- method << "yield self if block_given?"
+ method << "yield self if block_given? && !halted"
reverse_each do |callback|
method << callback.end(key, options)
end
@@ -365,7 +365,7 @@ class CallbackTerminator
save_callback :after, :third
- attr_reader :history
+ attr_reader :history, :saved
def initialize
@history = []
end
@@ -390,7 +390,9 @@ def third
end
def save
- _run_save_callbacks
+ _run_save_callbacks do
+ @saved = true
+ end
end
end
@@ -400,13 +402,19 @@ def test_termination
terminator.save
assert_equal ["first", "second", "third", "second", "first"], terminator.history
end
+
+ def test_block_never_called_if_terminated
+ obj = CallbackTerminator.new
+ obj.save
+ assert !obj.saved
+ end
end
class HyphenatedKeyTest < Test::Unit::TestCase
def test_save
obj = HyphenatedCallbacks.new
obj.save
assert_equal obj.stuff, "OMG"
- end
+ end
end
end

0 comments on commit c1d120a

Please sign in to comment.