diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-02-17 22:52:55 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-02-17 22:52:55 +0000 |
commit | 23e58a0552b4febd9372ee4642b0da886d92fd7a (patch) | |
tree | c543dd999b439f814daac060098e5d98758102ee | |
parent | 5457770a36deef3047e37b5e5737b3fbc4705b00 (diff) | |
download | rails-23e58a0552b4febd9372ee4642b0da886d92fd7a.tar.gz rails-23e58a0552b4febd9372ee4642b0da886d92fd7a.tar.bz2 rails-23e58a0552b4febd9372ee4642b0da886d92fd7a.zip |
Fix observed_class. References #11099.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8889 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | activerecord/lib/active_record/observer.rb | 2 | ||||
-rwxr-xr-x | activerecord/test/cases/lifecycle_test.rb | 11 |
2 files changed, 6 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/observer.rb b/activerecord/lib/active_record/observer.rb index 4e801a5843..2b0728fc25 100644 --- a/activerecord/lib/active_record/observer.rb +++ b/activerecord/lib/active_record/observer.rb @@ -153,7 +153,7 @@ module ActiveRecord # The class observed by default is inferred from the observer's class name: # assert_equal Person, PersonObserver.observed_class def observed_class - if observed_class_name = /(.*)Observer/.match(name)[1] + if observed_class_name = name[/(.*)Observer/, 1] observed_class_name.constantize else nil diff --git a/activerecord/test/cases/lifecycle_test.rb b/activerecord/test/cases/lifecycle_test.rb index 5800806e9e..0df7f4690d 100755 --- a/activerecord/test/cases/lifecycle_test.rb +++ b/activerecord/test/cases/lifecycle_test.rb @@ -26,7 +26,7 @@ class TopicManualObserver end end -class TopicaObserver < ActiveRecord::Observer +class TopicaAuditor < ActiveRecord::Observer observe :topic attr_reader :topic @@ -95,7 +95,9 @@ class LifecycleTest < ActiveRecord::TestCase end def test_auto_observer - topic_observer = TopicaObserver.instance + topic_observer = TopicaAuditor.instance + assert_nil TopicaAuditor.observed_class + assert_equal [Topic], TopicaAuditor.instance.observed_classes.to_a topic = Topic.find(1) assert_equal topic.title, topic_observer.topic.title @@ -103,6 +105,7 @@ class LifecycleTest < ActiveRecord::TestCase def test_inferred_auto_observer topic_observer = TopicObserver.instance + assert_equal Topic, TopicObserver.observed_class topic = Topic.find(1) assert_equal topic.title, topic_observer.topic.title @@ -134,8 +137,4 @@ class LifecycleTest < ActiveRecord::TestCase def test_invalid_observer assert_raise(ArgumentError) { Topic.observers = Object.new; Topic.instantiate_observers } end - - def test_getting_observed_class_from_class_name - assert_equal Topic, TopicObserver.observed_class - end end |