aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-02-15 23:09:51 +0000
committerMichael Koziarski <michael@koziarski.com>2008-02-15 23:09:51 +0000
commitf3fd2b18b743413d2260f4d54c63ef7375053fd7 (patch)
tree764ac68237b2765228e78f509bffe3768d9a7e53
parentc55120c8e6922146fa50bf1e4f4d87d4820e09dc (diff)
downloadrails-f3fd2b18b743413d2260f4d54c63ef7375053fd7.tar.gz
rails-f3fd2b18b743413d2260f4d54c63ef7375053fd7.tar.bz2
rails-f3fd2b18b743413d2260f4d54c63ef7375053fd7.zip
Add test for Observer#observer_class and change the implementation slightly. Closes #11099 [ernesto.jimenez]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8875 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/lib/active_record/observer.rb6
-rwxr-xr-xactiverecord/test/cases/lifecycle_test.rb4
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