aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-19 17:41:17 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-19 18:11:44 -0700
commit67247ca8ee850223193a5fe77f5460aefc0336c0 (patch)
tree8870ef4ccd99585d8a7a1628f4f5e217ad711cc6 /activesupport/test
parent36058f45040b5559fd8f6a44a17ead27a6b3d2f7 (diff)
downloadrails-67247ca8ee850223193a5fe77f5460aefc0336c0.tar.gz
rails-67247ca8ee850223193a5fe77f5460aefc0336c0.tar.bz2
rails-67247ca8ee850223193a5fe77f5460aefc0336c0.zip
Corrected new callbacks semantics with regards to using objects for around filters.
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/new_callbacks_test.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/activesupport/test/new_callbacks_test.rb b/activesupport/test/new_callbacks_test.rb
index dec6106ac1..7bec47224d 100644
--- a/activesupport/test/new_callbacks_test.rb
+++ b/activesupport/test/new_callbacks_test.rb
@@ -396,6 +396,68 @@ module NewCallbacksTest
end
end
+ class CallbackObject
+ def before_save(caller)
+ caller.record << "before"
+ end
+
+ def around_save(caller)
+ caller.record << "around before"
+ yield
+ caller.record << "around after"
+ end
+ end
+
+ class UsingObjectBefore
+ include ActiveSupport::NewCallbacks
+
+ define_callbacks :save
+ save_callback :before, CallbackObject.new
+
+ attr_accessor :record
+ def initialize
+ @record = []
+ end
+
+ def save
+ _run_save_callbacks do
+ @record << "yielded"
+ end
+ end
+ end
+
+ class UsingObjectAround
+ include ActiveSupport::NewCallbacks
+
+ define_callbacks :save
+ save_callback :around, CallbackObject.new
+
+ attr_accessor :record
+ def initialize
+ @record = []
+ end
+
+ def save
+ _run_save_callbacks do
+ @record << "yielded"
+ end
+ end
+ end
+
+ class UsingObjectTest < Test::Unit::TestCase
+ def test_before_object
+ u = UsingObjectBefore.new
+ u.save
+ assert_equal ["before", "yielded"], u.record
+ end
+
+ def test_around_object
+ u = UsingObjectAround.new
+ u.save
+ assert_equal ["around before", "yielded", "around after"], u.record
+ end
+ end
+
class CallbackTerminatorTest < Test::Unit::TestCase
def test_termination
terminator = CallbackTerminator.new