1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
Michael Koziarski 2008-02-15 23:09:51 +00:00
parent c55120c8e6
commit f3fd2b18b7
2 changed files with 7 additions and 3 deletions

View file

@ -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

View file

@ -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