From 50fbb7405665ba1c2b7c6f23574053a4764cef7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 1 Jan 2010 01:48:12 +0100 Subject: Fix inheritance issue with new callbacks. --- activesupport/test/callback_inheritance_test.rb | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/callback_inheritance_test.rb b/activesupport/test/callback_inheritance_test.rb index 18721eab19..2e978f01be 100644 --- a/activesupport/test/callback_inheritance_test.rb +++ b/activesupport/test/callback_inheritance_test.rb @@ -56,6 +56,31 @@ class Child < GrandParent end end +class EmptyParent + include ActiveSupport::Callbacks + + def performed? + @performed ||= false + end + + define_callbacks :dispatch + + def perform! + @performed = true + end + + def dispatch + _run_dispatch_callbacks + self + end +end + +class EmptyChild < EmptyParent + set_callback :dispatch, :before, :do_nothing + + def do_nothing + end +end class BasicCallbacksTest < Test::Unit::TestCase def setup @@ -113,3 +138,13 @@ class InheritedCallbacksTest2 < Test::Unit::TestCase assert_equal %w(before1 before2 update after2 after1), @update2.log end end + +class DynamicInheritedCallbacks < Test::Unit::TestCase + def test_callbacks_looks_to_the_superclass_before_running + child = EmptyChild.new.dispatch + assert !child.performed? + EmptyParent.set_callback :dispatch, :before, :perform! + child = EmptyChild.new.dispatch + assert child.performed? + end +end -- cgit v1.2.3