Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tests for issue #1360

  • Loading branch information...
commit 842043e3523275703cc574a3b33c3f6457a2dc29 1 parent 9d17913
@farleyknight farleyknight authored jonleighton committed
View
9 activerecord/test/cases/associations/has_many_associations_test.rb
@@ -2,6 +2,7 @@
require 'models/developer'
require 'models/project'
require 'models/company'
+require 'models/contract'
require 'models/topic'
require 'models/reply'
require 'models/category'
@@ -1475,4 +1476,12 @@ def test_abstract_class_with_polymorphic_has_many
tagging = Tagging.create! :taggable => post
assert_equal [tagging], post.taggings
end
+
+ def test_dont_call_save_callbacks_twice_on_has_many
+ firm = companies(:first_firm)
+ contract = firm.contracts.create!
+
+ assert_equal 1, contract.hi_count
+ assert_equal 1, contract.bye_count
+ end
end
View
15 activerecord/test/models/contract.rb
@@ -1,4 +1,19 @@
class Contract < ActiveRecord::Base
belongs_to :company
belongs_to :developer
+
+ before_save :hi
+ after_save :bye
+
+ attr_accessor :hi_count, :bye_count
+
+ def hi
+ @hi_count ||= 0
+ @hi_count += 1
+ end
+
+ def bye
+ @bye_count ||= 0
+ @bye_count += 1
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.