diff options
author | Myron Marston <myron.marston@gmail.com> | 2011-08-12 19:58:37 -0700 |
---|---|---|
committer | Myron Marston <myron.marston@gmail.com> | 2011-08-12 20:48:44 -0700 |
commit | d3c15a1d31d77e44b142c96cb55b654f3552a89d (patch) | |
tree | 6da096998bbd1c3a0764a10a3c933f943b6e973a /activerecord/test/cases | |
parent | 943a37348a9fdef73670be3d8452d436b7db0e69 (diff) | |
download | rails-d3c15a1d31d77e44b142c96cb55b654f3552a89d.tar.gz rails-d3c15a1d31d77e44b142c96cb55b654f3552a89d.tar.bz2 rails-d3c15a1d31d77e44b142c96cb55b654f3552a89d.zip |
Allow ActiveRecord observers to be disabled.
We have to use Observer#update rather than Observer#send since the enabled state is checked in #update before forwarding the method call on.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/lifecycle_test.rb | 12 |
1 files changed, 12 insertions, 0 deletions
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 |