aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases
diff options
context:
space:
mode:
authorMyron Marston <myron.marston@gmail.com>2011-08-12 19:58:37 -0700
committerMyron Marston <myron.marston@gmail.com>2011-08-12 20:48:44 -0700
commitd3c15a1d31d77e44b142c96cb55b654f3552a89d (patch)
tree6da096998bbd1c3a0764a10a3c933f943b6e973a /activemodel/test/cases
parent943a37348a9fdef73670be3d8452d436b7db0e69 (diff)
downloadrails-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 'activemodel/test/cases')
-rw-r--r--activemodel/test/cases/observing_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activemodel/test/cases/observing_test.rb b/activemodel/test/cases/observing_test.rb
index 99b1f407ae..f6ec24ae57 100644
--- a/activemodel/test/cases/observing_test.rb
+++ b/activemodel/test/cases/observing_test.rb
@@ -17,6 +17,10 @@ class FooObserver < ActiveModel::Observer
def on_spec(record)
stub.event_with(record) if stub
end
+
+ def around_save(record)
+ yield :in_around_save
+ end
end
class Foo
@@ -133,4 +137,12 @@ class ObserverTest < ActiveModel::TestCase
foo = Foo.new
Foo.send(:notify_observers, :whatever, foo)
end
+
+ test "update passes a block on to the observer" do
+ yielded_value = nil
+ FooObserver.instance.update(:around_save, Foo.new) do |val|
+ yielded_value = val
+ end
+ assert_equal :in_around_save, yielded_value
+ end
end