aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@github.com>2018-11-20 09:26:55 -0800
committerGitHub <noreply@github.com>2018-11-20 09:26:55 -0800
commit023a840f5f10c5a611a0618ff8ea9e16cd771f93 (patch)
tree11f22cbd809078856f9f99c196f3e1453252faef /activerecord/test
parentdc28cf8b0420774ae8e0d4410cdef0098ba34337 (diff)
parentf9157587c9d61a0e24a0dcba7b31aa698ddeb641 (diff)
downloadrails-023a840f5f10c5a611a0618ff8ea9e16cd771f93.tar.gz
rails-023a840f5f10c5a611a0618ff8ea9e16cd771f93.tar.bz2
rails-023a840f5f10c5a611a0618ff8ea9e16cd771f93.zip
Merge pull request #33954 from febeling/inconsistent-assignment-has-many-through-33942
Fix handling of duplicates for `replace` on has_many-through
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb10
1 files changed, 10 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 7b405c74c4..cf514957ca 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -586,6 +586,16 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_not_includes posts(:welcome).reload.people.reload, people(:michael)
end
+ def test_replace_association_with_duplicates
+ post = posts(:thinking)
+ person = people(:david)
+
+ assert_difference "post.people.count", 2 do
+ post.people = [person]
+ post.people = [person, person]
+ end
+ end
+
def test_replace_order_is_preserved
posts(:welcome).people.clear
posts(:welcome).people = [people(:david), people(:michael)]