Skip to content
This repository
Browse code

Observers not longer add an after_find method to the observed class.

[#625 state:resolved]
  • Loading branch information...
commit fbef982e4b906b879240a35a1ecff447007da6b2 1 parent c7acfbb
authored July 15, 2008 jeremy committed July 15, 2008
9  activerecord/lib/active_record/observer.rb
@@ -20,7 +20,7 @@ module ClassMethods
20 20
       #   ActiveRecord::Base.observers = Cacher, GarbageCollector
21 21
       #
22 22
       # Note: Setting this does not instantiate the observers yet. +instantiate_observers+ is
23  
-      # called during startup, and before each development request.  
  23
+      # called during startup, and before each development request.
24 24
       def observers=(*observers)
25 25
         @observers = observers.flatten
26 26
       end
@@ -130,11 +130,11 @@ def inherited(subclass)
130 130
   # Observers register themselves in the model class they observe, since it is the class that
131 131
   # notifies them of events when they occur. As a side-effect, when an observer is loaded its
132 132
   # corresponding model class is loaded.
133  
-  # 
  133
+  #
134 134
   # Up to (and including) Rails 2.0.2 observers were instantiated between plugins and
135  
-  # application initializers. Now observers are loaded after application initializers, 
  135
+  # application initializers. Now observers are loaded after application initializers,
136 136
   # so observed models can make use of extensions.
137  
-  # 
  137
+  #
138 138
   # If by any chance you are using observed models in the initialization you can still
139 139
   # load their observers by calling <tt>ModelObserver.instance</tt> before. Observers are
140 140
   # singletons and that call instantiates and registers them.
@@ -189,7 +189,6 @@ def observed_subclasses
189 189
 
190 190
       def add_observer!(klass)
191 191
         klass.add_observer(self)
192  
-        klass.class_eval 'def after_find() end' unless klass.method_defined?(:after_find)
193 192
       end
194 193
   end
195 194
 end
12  activerecord/test/cases/lifecycle_test.rb
@@ -143,12 +143,20 @@ def test_observing_subclasses
143 143
     assert_equal developer.name, multi_observer.record.name
144 144
   end
145 145
 
146  
-  def test_observing_after_find_when_not_defined_on_the_model
  146
+  def test_after_find_cannot_be_observed_when_its_not_defined_on_the_model
147 147
     observer = MinimalisticObserver.instance
148 148
     assert_equal Minimalistic, MinimalisticObserver.observed_class
149 149
 
150 150
     minimalistic = Minimalistic.find(1)
151  
-    assert_equal minimalistic, observer.minimalistic
  151
+    assert_nil observer.minimalistic
  152
+  end
  153
+
  154
+  def test_after_find_can_be_observed_when_its_defined_on_the_model
  155
+    observer = TopicObserver.instance
  156
+    assert_equal Topic, TopicObserver.observed_class
  157
+
  158
+    topic = Topic.find(1)
  159
+    assert_equal topic, observer.topic
152 160
   end
153 161
 
154 162
   def test_invalid_observer

0 notes on commit fbef982

Please sign in to comment.
Something went wrong with that request. Please try again.