diff options
author | Robert Pankowecki (Gavdi) <rpa@gavdi.com> | 2010-11-26 19:16:13 +0100 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-09 10:41:43 -0800 |
commit | bba3dacc3dc6ac379209f2eda0da5d2dd93d6b04 (patch) | |
tree | d2434eee1764f42b919522f9f944a50ae745c533 /activerecord/test/cases | |
parent | e12810178cebc0c40a90b4aba3976537852b71b4 (diff) | |
download | rails-bba3dacc3dc6ac379209f2eda0da5d2dd93d6b04.tar.gz rails-bba3dacc3dc6ac379209f2eda0da5d2dd93d6b04.tar.bz2 rails-bba3dacc3dc6ac379209f2eda0da5d2dd93d6b04.zip |
Simplifies observer implementation [#6065 state:resolved]
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/lifecycle_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/cases/lifecycle_test.rb b/activerecord/test/cases/lifecycle_test.rb index 233338498f..b8c3ffb9cb 100644 --- a/activerecord/test/cases/lifecycle_test.rb +++ b/activerecord/test/cases/lifecycle_test.rb @@ -9,10 +9,19 @@ class SpecialDeveloper < Developer; end class SalaryChecker < ActiveRecord::Observer observe :special_developer + attr_accessor :last_saved def before_save(developer) return developer.salary > 80000 end + + module Implementation + def after_save(developer) + self.last_saved = developer + end + end + include Implementation + end class TopicaAuditor < ActiveRecord::Observer @@ -179,4 +188,11 @@ class LifecycleTest < ActiveRecord::TestCase developer = SpecialDeveloper.new :name => 'Rookie', :salary => 50000 assert !developer.save, "allowed to save a developer with too low salary" end + + test "able to call methods defined with included module" do # https://rails.lighthouseapp.com/projects/8994/tickets/6065-activerecordobserver-is-not-aware-of-method-added-by-including-modules + SalaryChecker.instance # activate + developer = SpecialDeveloper.create! :name => 'Roger', :salary => 100000 + assert_equal developer, SalaryChecker.instance.last_saved + end + end |