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:
parent
c55120c8e6
commit
f3fd2b18b7
2 changed files with 7 additions and 3 deletions
|
@ -151,10 +151,10 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
# The class observed by default is inferred from the observer's class name:
|
# 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
|
def observed_class
|
||||||
if observed_class_name = name.scan(/(.*)Observer/)[0]
|
if observed_class_name = /(.*)Observer/.match(name)[1]
|
||||||
observed_class_name[0].constantize
|
observed_class_name.constantize
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -134,4 +134,8 @@ class LifecycleTest < ActiveRecord::TestCase
|
||||||
def test_invalid_observer
|
def test_invalid_observer
|
||||||
assert_raise(ArgumentError) { Topic.observers = Object.new; Topic.instantiate_observers }
|
assert_raise(ArgumentError) { Topic.observers = Object.new; Topic.instantiate_observers }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_getting_observed_class_from_class_name
|
||||||
|
assert_equal Topic, TopicObserver.observed_class
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue