diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-07-15 21:55:28 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-07-15 22:01:02 -0500 |
commit | be078ee162fcae883a5621a30929879cd783a238 (patch) | |
tree | 6f6b6f31fef96c98771aff9f7a9da5cc0836da51 /activesupport/test | |
parent | f4f6e57e8c2a446a4a600576f0caf0fb8921ba13 (diff) | |
download | rails-be078ee162fcae883a5621a30929879cd783a238.tar.gz rails-be078ee162fcae883a5621a30929879cd783a238.tar.bz2 rails-be078ee162fcae883a5621a30929879cd783a238.zip |
Run callbacks from object's metaclass [#575 state:resolved]
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/callbacks_test.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index 7f71ca2262..c3f683bdb5 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -84,6 +84,30 @@ class CallbacksTest < Test::Unit::TestCase end end +class MetaclassCallbacksTest < Test::Unit::TestCase + module ModuleWithCallbacks + def self.extended(object) + object.metaclass.before_save :raise_metaclass_callback_called + end + + def module_callback_called? + @module_callback_called ||= false + end + + def raise_metaclass_callback_called + @module_callback_called = true + end + end + + def test_metaclass_callbacks + person = Person.new + person.extend(ModuleWithCallbacks) + assert !person.module_callback_called? + person.save + assert person.module_callback_called? + end +end + class ConditionalCallbackTest < Test::Unit::TestCase def test_save_conditional_person person = ConditionalPerson.new |