public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Observers not longer add an after_find method to the observed class.

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

Comments