aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-19 17:21:06 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-06-19 17:21:06 -0300
commitefb41c6abc39b71183d3f13a267f801576a399cb (patch)
tree498f59ddbf51a90a3ca9bc368701c8191df8d3d9 /activerecord/test
parent1fa3a241c2485654f3cfa2287c19cd6785d265d9 (diff)
parent068f092ced8483e557725542dd919ab7c516e567 (diff)
downloadrails-efb41c6abc39b71183d3f13a267f801576a399cb.tar.gz
rails-efb41c6abc39b71183d3f13a267f801576a399cb.tar.bz2
rails-efb41c6abc39b71183d3f13a267f801576a399cb.zip
Merge pull request #15728 from sgrif/sg-double-save-hm-t
Don't save through records twice Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index ad2aa99af5..0fa34e829e 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -1139,7 +1139,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_equal 2, post.lazy_readers_unscope_skimmers.to_a.size
assert_equal 2, post.lazy_people_unscope_skimmers.to_a.size
end
-
+
def test_has_many_through_add_with_sti_middle_relation
club = SuperClub.create!(name: 'Fight Club')
member = Member.create!(name: 'Tyler Durden')
@@ -1147,4 +1147,23 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
club.members << member
assert_equal 1, SuperMembership.where(member_id: member.id, club_id: club.id).count
end
+
+ class ClubWithCallbacks < ActiveRecord::Base
+ self.table_name = 'clubs'
+ after_create :add_a_member
+
+ has_many :memberships, inverse_of: :club, foreign_key: :club_id
+ has_many :members, through: :memberships
+
+ def add_a_member
+ members << Member.last
+ end
+ end
+
+ def test_has_many_with_callback_before_association
+ Member.create!
+ club = ClubWithCallbacks.create!
+
+ assert_equal 1, club.reload.memberships.count
+ end
end