diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-10 16:21:16 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-10 16:42:16 +0900 |
commit | faf07d1468af06bb3f7f5dd0776d77dd252af3b6 (patch) | |
tree | 6bdffd96373b85eb852e6b5795c5c101eed916ac /activerecord/test/cases/associations/has_many_through_associations_test.rb | |
parent | 7cb3e8b8efb193c13281c0d6c0354bbcc91c3b8e (diff) | |
parent | 332e7601a98ebff6a7494a556c7fe97c5691f085 (diff) | |
download | rails-faf07d1468af06bb3f7f5dd0776d77dd252af3b6.tar.gz rails-faf07d1468af06bb3f7f5dd0776d77dd252af3b6.tar.bz2 rails-faf07d1468af06bb3f7f5dd0776d77dd252af3b6.zip |
Merge pull request #28155 from lcreid/belongs_to
Fix "autosave: true" on belongs_to of join model causes invalid records to be saved
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.rb | 16 |
1 files changed, 16 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 fa540c9dab..c13789f7ec 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -33,6 +33,9 @@ require "models/organization" require "models/user" require "models/family" require "models/family_tree" +require "models/section" +require "models/seminar" +require "models/session" class HasManyThroughAssociationsTest < ActiveRecord::TestCase fixtures :posts, :readers, :people, :comments, :authors, :categories, :taggings, :tags, @@ -1492,6 +1495,19 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase end end + def test_circular_autosave_association_correctly_saves_multiple_records + cs180 = Seminar.new(name: "CS180") + fall = Session.new(name: "Fall") + sections = [ + cs180.sections.build(short_name: "A"), + cs180.sections.build(short_name: "B"), + ] + fall.sections << sections + fall.save! + fall.reload + assert_equal sections, fall.sections.sort_by(&:id) + end + private def make_model(name) Class.new(ActiveRecord::Base) { define_singleton_method(:name) { name } } |