Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix #7127. Don't call after_* when around_* returns false.

  • Loading branch information...
commit 3d12ae21b201737f9460e961132a640f31de4341 1 parent 287a8d8
Toshinori Kajihara authored
14 activemodel/test/cases/callbacks_test.rb
View
@@ -111,4 +111,18 @@ class Violin2 < Violin
assert_equal ["callback1", "callback2"], Violin2.new.create.history
end
+ class Saxophone
+ attr_reader :called
+ extend ActiveModel::Callbacks
+ define_model_callbacks :create
+ def create; run_callbacks(:create) {}; end
+ around_create { false }
+ after_create { @called = true }
+ end
+
+ test "don't call after_create if around_create returns false" do
+ sax = Saxophone.new
+ sax.create
+ assert !sax.called
+ end
end
5 activesupport/lib/active_support/callbacks.rb
View
@@ -172,10 +172,13 @@ def apply(code)
when :around
name = define_conditional_callback
<<-RUBY_EVAL
- #{name}(halted) do
+ called = false
+ result = #{name}(halted) do
#{code}
+ called = true
value
end
+ value = result unless called
RUBY_EVAL
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.