diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-06-07 04:28:23 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-06-07 04:28:23 +0900 |
commit | 48c95cf7e591ed3b683705ded92c6d7c7518aaec (patch) | |
tree | 708b0f3732c82a33c099588f007bc50502bb4975 /activerecord/test/cases | |
parent | 86e42b53662f535ee484630144e27ee684e8e8dc (diff) | |
download | rails-48c95cf7e591ed3b683705ded92c6d7c7518aaec.tar.gz rails-48c95cf7e591ed3b683705ded92c6d7c7518aaec.tar.bz2 rails-48c95cf7e591ed3b683705ded92c6d7c7518aaec.zip |
Reuse existing model for testing duplicated children records
Follow up of #32952.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/autosave_association_test.rb | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index cf93d42942..ade1f4b44d 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -27,7 +27,6 @@ require "models/member_detail" require "models/organization" require "models/guitar" require "models/tuning_peg" -require "models/topic" require "models/reply" class TestAutosaveAssociationsInGeneral < ActiveRecord::TestCase @@ -560,19 +559,18 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa 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 + assert_no_difference "Reply.count" do + assert_no_difference "SillyUniqueReply.count" do + reply = Reply.new + reply.silly_unique_replies.build([ + { content: "Best content" }, + { content: "Best content" } + ]) + + assert_not reply.save + assert_not_empty reply.errors + end + end end def test_invalid_build |