aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <github@marc-andre.ca>2012-04-29 21:50:48 -0400
committerMarc-Andre Lafortune <github@marc-andre.ca>2012-04-29 21:51:50 -0400
commitbad44e4f8f690039bd0db92ac25f10af536c6e71 (patch)
tree5818243402efeaf48c43af6d691f169a9089c059 /activemodel/test
parentad2c5ea2786817592014fae09934398173c1a7f9 (diff)
downloadrails-bad44e4f8f690039bd0db92ac25f10af536c6e71.tar.gz
rails-bad44e4f8f690039bd0db92ac25f10af536c6e71.tar.bz2
rails-bad44e4f8f690039bd0db92ac25f10af536c6e71.zip
Fix Observer by acting on singleton class [#3505]
Also [issue #1034] [pull #6068]
Diffstat (limited to 'activemodel/test')
-rw-r--r--activemodel/test/cases/observing_test.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/activemodel/test/cases/observing_test.rb b/activemodel/test/cases/observing_test.rb
index df070d2d8e..096a309335 100644
--- a/activemodel/test/cases/observing_test.rb
+++ b/activemodel/test/cases/observing_test.rb
@@ -80,13 +80,13 @@ end
class ObserverTest < ActiveModel::TestCase
def setup
ObservedModel.observers = :foo_observer
- FooObserver.instance_eval do
+ FooObserver.singleton_class.instance_eval do
alias_method :original_observed_classes, :observed_classes
end
end
def teardown
- FooObserver.instance_eval do
+ FooObserver.singleton_class.instance_eval do
undef_method :observed_classes
alias_method :observed_classes, :original_observed_classes
end
@@ -145,4 +145,15 @@ class ObserverTest < ActiveModel::TestCase
end
assert_equal :in_around_save, yielded_value
end
+
+ test "observe redefines observed_classes class method" do
+ class BarObserver < ActiveModel::Observer
+ observe :foo
+ end
+
+ assert_equal [Foo], BarObserver.observed_classes
+
+ BarObserver.observe(ObservedModel)
+ assert_equal [ObservedModel], BarObserver.observed_classes
+ end
end