diff options
author | José Valim <jose.valim@gmail.com> | 2011-08-13 08:40:13 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-08-13 08:40:13 -0700 |
commit | 291072a64a2b191816f395b25aae4a50d2dcfe16 (patch) | |
tree | 9f4f4a80ce6058a5c298fd79ae8cde96fd45b967 /activerecord | |
parent | 34689c40a03c9921b5c43ac1e120a9885edded73 (diff) | |
parent | d3c15a1d31d77e44b142c96cb55b654f3552a89d (diff) | |
download | rails-291072a64a2b191816f395b25aae4a50d2dcfe16.tar.gz rails-291072a64a2b191816f395b25aae4a50d2dcfe16.tar.bz2 rails-291072a64a2b191816f395b25aae4a50d2dcfe16.zip |
Merge pull request #2514 from myronmarston/fix_active_record_observer_disabling
Allow ActiveRecord observers to be disabled.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/observer.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/lifecycle_test.rb | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/observer.rb b/activerecord/lib/active_record/observer.rb index 5a5351b517..fdf17c003c 100644 --- a/activerecord/lib/active_record/observer.rb +++ b/activerecord/lib/active_record/observer.rb @@ -111,7 +111,7 @@ module ActiveRecord callback_meth = :"_notify_#{observer_name}_for_#{callback}" unless klass.respond_to?(callback_meth) klass.send(:define_method, callback_meth) do |&block| - observer.send(callback, self, &block) + observer.update(callback, self, &block) end klass.send(callback, callback_meth) end diff --git a/activerecord/test/cases/lifecycle_test.rb b/activerecord/test/cases/lifecycle_test.rb index 643e949087..75e5dfa49b 100644 --- a/activerecord/test/cases/lifecycle_test.rb +++ b/activerecord/test/cases/lifecycle_test.rb @@ -231,6 +231,18 @@ class LifecycleTest < ActiveRecord::TestCase assert_not_nil observer.topic_ids.last end + test "able to disable observers" do + observer = DeveloperObserver.instance # activate + observer.calls.clear + + ActiveRecord::Base.observers.disable DeveloperObserver do + Developer.create! :name => 'Ancestor', :salary => 100000 + SpecialDeveloper.create! :name => 'Descendent', :salary => 100000 + end + + assert_equal [], observer.calls + end + def test_observer_is_called_once observer = DeveloperObserver.instance # activate observer.calls.clear |