diff options
author | Rolf Timmermans <r.timmermans@voormedia.com> | 2011-03-12 23:05:52 +0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-03-13 01:35:29 +0800 |
commit | 1a3fe8ce42e202630e6b1d8cf7137002e270ebdb (patch) | |
tree | ededececae28f3ca6369f53c64085fae9b0f9c60 /activesupport/test | |
parent | 46f6a2e3889bae420589f429b09722a37dbdf18d (diff) | |
download | rails-1a3fe8ce42e202630e6b1d8cf7137002e270ebdb.tar.gz rails-1a3fe8ce42e202630e6b1d8cf7137002e270ebdb.tar.bz2 rails-1a3fe8ce42e202630e6b1d8cf7137002e270ebdb.zip |
Prevent callbacks in child classes from being executed more than once.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/callback_inheritance_test.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/activesupport/test/callback_inheritance_test.rb b/activesupport/test/callback_inheritance_test.rb index 71249050fc..d569cbb4fb 100644 --- a/activesupport/test/callback_inheritance_test.rb +++ b/activesupport/test/callback_inheritance_test.rb @@ -82,6 +82,30 @@ class EmptyChild < EmptyParent end end +class CountingParent + include ActiveSupport::Callbacks + + attr_reader :count + + define_callbacks :dispatch + + def initialize + @count = 0 + end + + def count! + @count += 1 + end + + def dispatch + run_callbacks(:dispatch) + self + end +end + +class CountingChild < CountingParent +end + class BasicCallbacksTest < Test::Unit::TestCase def setup @index = GrandParent.new("index").dispatch @@ -147,4 +171,10 @@ class DynamicInheritedCallbacks < Test::Unit::TestCase child = EmptyChild.new.dispatch assert child.performed? end + + def test_callbacks_should_be_performed_once_in_child_class + CountingParent.set_callback(:dispatch, :before) { count! } + child = CountingChild.new.dispatch + assert_equal 1, child.count + end end |