diff options
author | Hemant Kumar <hkumar@crri.co.in> | 2011-05-07 03:03:41 +0530 |
---|---|---|
committer | Hemant Kumar <hkumar@crri.co.in> | 2011-05-07 03:03:41 +0530 |
commit | 20c35bca5adb515b3c4ec6c2b10cba1f6c0217aa (patch) | |
tree | 503df8defcf0a315432a450d8ec0270528e449be /activerecord/test | |
parent | 9c2c25c1a1343937e96eed81e38ef4f9fb06ce11 (diff) | |
download | rails-20c35bca5adb515b3c4ec6c2b10cba1f6c0217aa.tar.gz rails-20c35bca5adb515b3c4ec6c2b10cba1f6c0217aa.tar.bz2 rails-20c35bca5adb515b3c4ec6c2b10cba1f6c0217aa.zip |
fix yield not working from around filter of observers, fixes Github#329
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/lifecycle_test.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/test/cases/lifecycle_test.rb b/activerecord/test/cases/lifecycle_test.rb index 6cd8494c9e..643e949087 100644 --- a/activerecord/test/cases/lifecycle_test.rb +++ b/activerecord/test/cases/lifecycle_test.rb @@ -107,6 +107,23 @@ class ValidatedCommentObserver < ActiveRecord::Observer end end + +class AroundTopic < Topic +end + +class AroundTopicObserver < ActiveRecord::Observer + observe :around_topic + def topic_ids + @topic_ids ||= [] + end + + def around_save(topic) + topic_ids << topic.id + yield(topic) + topic_ids << topic.id + end +end + class LifecycleTest < ActiveRecord::TestCase fixtures :topics, :developers, :minimalistics @@ -206,6 +223,14 @@ class LifecycleTest < ActiveRecord::TestCase assert_equal developer, SalaryChecker.instance.last_saved end + test "around filter from observer should accept block" do + observer = AroundTopicObserver.instance + topic = AroundTopic.new + topic.save + assert_nil observer.topic_ids.first + assert_not_nil observer.topic_ids.last + end + def test_observer_is_called_once observer = DeveloperObserver.instance # activate observer.calls.clear |