aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_through_associations_test.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-09-05 18:43:10 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-09-05 18:43:10 -0300
commitad4ea980900b96a92e8248bdc6c09973d6bd8254 (patch)
treea7a818098c1ea19f3757d99781d0c3f3670d499b /activerecord/test/cases/associations/has_many_through_associations_test.rb
parent31bfcdc77ca0d8cec9b5fe513bdc6f05814dd4f1 (diff)
downloadrails-ad4ea980900b96a92e8248bdc6c09973d6bd8254.tar.gz
rails-ad4ea980900b96a92e8248bdc6c09973d6bd8254.tar.bz2
rails-ad4ea980900b96a92e8248bdc6c09973d6bd8254.zip
Do not mark object as persisted after an association is saved
Callback order in Active Record objects are important. Users should not define callbacks before the association definition or surprising behaviours like the described at #3798 will happen. This callback order dependency is documented at https://github.com/rails/rails/blob/31bfcdc77ca0d8cec9b5fe513bdc6f05814dd4f1/activerecord/lib/active_record/associations.rb#L1222-1227. This reverts #15728. Fixes #16620.
Diffstat (limited to 'activerecord/test/cases/associations/has_many_through_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb19
1 files changed, 0 insertions, 19 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 d9659a72c5..cddf1a1f72 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -1147,23 +1147,4 @@ 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