diff options
author | George Ogata <george.ogata@gmail.com> | 2008-06-09 13:45:57 +1000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-06-17 19:45:18 +0100 |
commit | bc4a2f156b368334ca7267d15f4dd10864ac492d (patch) | |
tree | e5e94216fdbd306a9b753e5b14167d3cf17f33e4 /activerecord/test/cases | |
parent | 1b4b8fbbd95d7d674df7f013fd88b9b7f859a6f1 (diff) | |
download | rails-bc4a2f156b368334ca7267d15f4dd10864ac492d.tar.gz rails-bc4a2f156b368334ca7267d15f4dd10864ac492d.tar.bz2 rails-bc4a2f156b368334ca7267d15f4dd10864ac492d.zip |
Fix observers that use after_find. [#375 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test/cases')
-rwxr-xr-x | activerecord/test/cases/lifecycle_test.rb | 17 |
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 |