Skip to content

Commit

Permalink
Don't run the action if callbacks are halted.
Browse files Browse the repository at this point in the history
  In AbstractController, this means that response_body is not empty
  • Loading branch information
Yehuda Katz + Carl Lerche committed May 11, 2009
1 parent 34caf4f commit c1d120a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/abstract/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/new_callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions activesupport/test/new_callbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class CallbackTerminator
save_callback :after, :third


attr_reader :history
attr_reader :history, :saved
def initialize
@history = []
end
Expand All @@ -390,7 +390,9 @@ def third
end

def save
_run_save_callbacks
_run_save_callbacks do
@saved = true
end
end
end

Expand All @@ -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.