aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/cases/lifecycle_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/test/cases/lifecycle_test.rb b/activerecord/test/cases/lifecycle_test.rb
index ddcacacc3a..258f7c7a0f 100755
--- a/activerecord/test/cases/lifecycle_test.rb
+++ b/activerecord/test/cases/lifecycle_test.rb
@@ -2,6 +2,7 @@ require "cases/helper"
require 'models/topic'
require 'models/developer'
require 'models/reply'
+require 'models/minimalistic'
class Topic; def after_find() end end
class Developer; def after_find() end end
@@ -44,6 +45,14 @@ class TopicObserver < ActiveRecord::Observer
end
end
+class MinimalisticObserver < ActiveRecord::Observer
+ attr_reader :minimalistic
+
+ def after_find(minimalistic)
+ @minimalistic = minimalistic
+ end
+end
+
class MultiObserver < ActiveRecord::Observer
attr_reader :record
@@ -134,6 +143,14 @@ class LifecycleTest < ActiveRecord::TestCase
assert_equal developer.name, multi_observer.record.name
end
+ def test_observing_after_find_when_not_defined_on_the_model
+ observer = MinimalisticObserver.instance
+ assert_equal Minimalistic, MinimalisticObserver.observed_class
+
+ minimalistic = Minimalistic.find(1)
+ assert_equal minimalistic, observer.minimalistic
+ end
+
def test_invalid_observer
assert_raise(ArgumentError) { Topic.observers = Object.new; Topic.instantiate_observers }
end