Permalink
Browse files

Fixed that Observers didn't observe sub-classes #627 [Florian Weber]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2263 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 9cc624d commit 6f95c49a15e85c007e9c94c107232f9fee600aa8 @dhh dhh committed Sep 19, 2005
Showing with 13 additions and 1 deletion.
  1. +2 −0 activerecord/CHANGELOG
  2. +3 −1 activerecord/lib/active_record/observer.rb
  3. +8 −0 activerecord/test/lifecycle_test.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that Observers didn't observe sub-classes #627 [Florian Weber]
+
* Fix eager loading error messages, allow :include to specify tables using strings or symbols. Closes #2222 [Marcel Molina]
* Added check for RAILS_CONNECTION_ADAPTERS on startup and only load the connection adapters specified within if its present (available in Rails through config.connection_adapters using the new config) #1958 [skae]
@@ -58,7 +58,9 @@ def self.observe(*models)
end
def initialize
- [ observed_class ].flatten.each do |klass|
+ observed_classes = [ observed_class ].flatten
+ observed_subclasses_class = observed_classes.collect {|c| c.send(:subclasses) }.flatten!
+ (observed_classes + observed_subclasses_class).each do |klass|
klass.add_observer(self)
klass.send(:define_method, :after_find) unless klass.respond_to?(:after_find)
end
@@ -5,6 +5,7 @@
class Topic; def after_find() end end
class Developer; def after_find() end end
+class SpecialDeveloper < Developer; end
class TopicManualObserver
include Singleton
@@ -105,4 +106,11 @@ def test_observing_two_classes
developer = Developer.find(1)
assert_equal multi_observer.record.name, developer.name
end
+
+ def test_observing_subclasses
+ multi_observer = MultiObserver.instance
+
+ developer = SpecialDeveloper.find(1)
+ assert_equal multi_observer.record.name, developer.name
+ end
end

0 comments on commit 6f95c49

Please sign in to comment.