aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/lifecycle_test.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/lifecycle_test.rb b/activerecord/test/cases/lifecycle_test.rb
index 0558deb71b..a42f5d9c9d 100644
--- a/activerecord/test/cases/lifecycle_test.rb
+++ b/activerecord/test/cases/lifecycle_test.rb
@@ -7,6 +7,12 @@ require 'models/comment'
class SpecialDeveloper < Developer; end
+class DeveloperObserver < ActiveRecord::Observer
+ def before_save(developer)
+ developer.salary += 1
+ end
+end
+
class SalaryChecker < ActiveRecord::Observer
observe :special_developer
attr_accessor :last_saved
@@ -196,4 +202,12 @@ class LifecycleTest < ActiveRecord::TestCase
assert_equal developer, SalaryChecker.instance.last_saved
end
+ test "callback observing the ancestor does not fire multiple times on descendent" do
+ DeveloperObserver.instance # activate
+ developer = Developer.create! :name => 'Ancestor', :salary => 100000
+ assert_equal 100001, developer.salary, 'ancestor callback fired multiple times'
+ developer = SpecialDeveloper.create! :name => 'Descendent', :salary => 100000
+ assert_equal 100001, developer.salary, 'descendent callback fired multiple times'
+ end
+
end