Permalink
Browse files

Add test for Observer#observer_class and change the implementation sl…

…ightly. Closes #11099 [ernesto.jimenez]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8875 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent c55120c commit f3fd2b18b743413d2260f4d54c63ef7375053fd7 @NZKoz NZKoz committed Feb 15, 2008
Showing with 7 additions and 3 deletions.
  1. +3 −3 activerecord/lib/active_record/observer.rb
  2. +4 −0 activerecord/test/cases/lifecycle_test.rb
@@ -151,10 +151,10 @@ def observe(*models)
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
@@ -134,4 +134,8 @@ def test_observing_subclasses
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

0 comments on commit f3fd2b1

Please sign in to comment.