diff options
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/autosave_association_test.rb | 26 | ||||
-rw-r--r-- | activerecord/test/models/reply.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/topic.rb | 1 |
3 files changed, 13 insertions, 19 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 diff --git a/activerecord/test/models/reply.rb b/activerecord/test/models/reply.rb index d178413fd7..0ea110f4f8 100644 --- a/activerecord/test/models/reply.rb +++ b/activerecord/test/models/reply.rb @@ -6,6 +6,7 @@ class Reply < Topic belongs_to :topic, foreign_key: "parent_id", counter_cache: true belongs_to :topic_with_primary_key, class_name: "Topic", primary_key: "title", foreign_key: "parent_title", counter_cache: "replies_count", touch: true has_many :replies, class_name: "SillyReply", dependent: :destroy, foreign_key: "parent_id" + has_many :silly_unique_replies, dependent: :destroy, foreign_key: "parent_id" end class UniqueReply < Reply @@ -14,10 +15,6 @@ class UniqueReply < Reply end class SillyUniqueReply < UniqueReply -end - -class ValidateUniqueContentReply < Reply - belongs_to :topic, foreign_key: "parent_id" validates :content, uniqueness: true end diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb index 8368405cef..72699046f9 100644 --- a/activerecord/test/models/topic.rb +++ b/activerecord/test/models/topic.rb @@ -47,7 +47,6 @@ class Topic < ActiveRecord::Base has_many :unique_replies, dependent: :destroy, foreign_key: "parent_id" has_many :silly_unique_replies, dependent: :destroy, foreign_key: "parent_id" - has_many :validate_unique_content_replies, dependent: :destroy, foreign_key: "parent_id" serialize :content |