diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/observer.rb | 6 | ||||
-rwxr-xr-x | activerecord/test/cases/lifecycle_test.rb | 4 |
2 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/observer.rb b/activerecord/lib/active_record/observer.rb index 6e4db637f5..4e801a5843 100644 --- a/activerecord/lib/active_record/observer.rb +++ b/activerecord/lib/active_record/observer.rb @@ -151,10 +151,10 @@ module ActiveRecord end # The class observed by default is inferred from the observer's class name: - # assert_equal [Person], PersonObserver.observed_class + # assert_equal Person, PersonObserver.observed_class def observed_class - if observed_class_name = name.scan(/(.*)Observer/)[0] - observed_class_name[0].constantize + if observed_class_name = /(.*)Observer/.match(name)[1] + observed_class_name.constantize else nil end diff --git a/activerecord/test/cases/lifecycle_test.rb b/activerecord/test/cases/lifecycle_test.rb index 7660254528..5800806e9e 100755 --- a/activerecord/test/cases/lifecycle_test.rb +++ b/activerecord/test/cases/lifecycle_test.rb @@ -134,4 +134,8 @@ 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 |