diff options
author | Santosh Wadghule <santosh.wadghule@gmail.com> | 2018-05-22 19:04:24 +0530 |
---|---|---|
committer | Santosh Wadghule <santosh.wadghule@gmail.com> | 2018-05-28 18:23:21 +0530 |
commit | d7a3f33dbd4726480fcbefc0c3c1270396f61fd2 (patch) | |
tree | c7fef63458aafa3893a8819ab3c918a0f6bc64b1 /activerecord/test/cases | |
parent | 2f76256127d35cfbfaadf162e4d8be2d0af4e453 (diff) | |
download | rails-d7a3f33dbd4726480fcbefc0c3c1270396f61fd2.tar.gz rails-d7a3f33dbd4726480fcbefc0c3c1270396f61fd2.tar.bz2 rails-d7a3f33dbd4726480fcbefc0c3c1270396f61fd2.zip |
Fix parent record should not get saved with duplicate children records
- Fixes #32940
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/autosave_association_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index 7355f4cd62..cf93d42942 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -27,6 +27,8 @@ require "models/member_detail" require "models/organization" require "models/guitar" require "models/tuning_peg" +require "models/topic" +require "models/reply" class TestAutosaveAssociationsInGeneral < ActiveRecord::TestCase def test_autosave_validation @@ -557,6 +559,22 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa assert_equal no_of_clients + 1, Client.count end + def test_parent_should_not_get_saved_with_duplicate_children_records + Topic.delete_all + + content = "Best content" + reply1 = ValidateUniqueContentReply.new(content: content) + reply2 = ValidateUniqueContentReply.new(content: content) + + topic = Topic.new(validate_unique_content_replies: [reply1, reply2]) + + assert_not topic.save + assert topic.errors.any? + + assert_equal 0, Topic.count + assert_equal 0, ValidateUniqueContentReply.count + end + def test_invalid_build new_client = companies(:first_firm).clients_of_firm.build assert_not_predicate new_client, :persisted? |