diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-01 00:51:47 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-01 01:34:32 +0900 |
commit | 7c3da6e0030aa080fcb89af58b094ed50d861a44 (patch) | |
tree | 730791b089da821ed9918210a0d725f66480ae9a | |
parent | 23125378673bcc606b274027666a126573e136f8 (diff) | |
download | rails-7c3da6e0030aa080fcb89af58b094ed50d861a44.tar.gz rails-7c3da6e0030aa080fcb89af58b094ed50d861a44.tar.bz2 rails-7c3da6e0030aa080fcb89af58b094ed50d861a44.zip |
Add regression test for has_many through record creation
#33729 affected the behavior of the has_many through record creation.
Since #33729, the intermediate reflection of simple has_many through
association has `inverse_of` to the association, it causes extra through
record creation, the extra through record required valid before the
association record is saved.
https://github.com/rails/rails/blob/23125378673bcc606b274027666a126573e136f8/activerecord/lib/active_record/associations/has_many_through_association.rb#L95-L102
I think that #33729 need to more work to care about has_many through
association, that PR should be reverted to not break existing apps.
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 4 | ||||
-rw-r--r-- | activerecord/test/models/subscription.rb | 2 |
2 files changed, 6 insertions, 0 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 bd535357ee..0133beccec 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -46,6 +46,10 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase Reader.create person_id: 0, post_id: 0 end + def test_has_many_through_create_record + assert books(:awdr).subscribers.create!(nick: "bob") + end + def test_marshal_dump preloaded = Post.includes(:first_blue_tags).first assert_equal preloaded, Marshal.load(Marshal.dump(preloaded)) diff --git a/activerecord/test/models/subscription.rb b/activerecord/test/models/subscription.rb index d1d5d21621..f87315fcd1 100644 --- a/activerecord/test/models/subscription.rb +++ b/activerecord/test/models/subscription.rb @@ -3,4 +3,6 @@ class Subscription < ActiveRecord::Base belongs_to :subscriber, counter_cache: :books_count belongs_to :book + + validates_presence_of :subscriber_id, :book_id end |