aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorTobias Kraze <tobias.kraze@makandra.de>2017-06-27 17:41:39 +0200
committerTobias Kraze <tobias.kraze@makandra.de>2017-06-28 14:18:48 +0200
commitc41247a3d273f415cf2c7aae7aff490234815ad9 (patch)
tree22c10ef00798382e0ca8537c58103fbaaf684911 /activerecord/test/cases
parent61cc630ac7e7f8554dc049a3e5a2509c00303ef8 (diff)
downloadrails-c41247a3d273f415cf2c7aae7aff490234815ad9.tar.gz
rails-c41247a3d273f415cf2c7aae7aff490234815ad9.tar.bz2
rails-c41247a3d273f415cf2c7aae7aff490234815ad9.zip
ActiveRecord: do not create "has many through" records that have been removed
If a record was built on a HasManyThroughAssociation, then removed, and then the record was saved, the removed record would be created anyways.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb11
1 files changed, 11 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 9156f6d57a..1c2138a3d0 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -319,6 +319,17 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_includes post.single_people, person
end
+ def test_build_then_remove_then_save
+ post = posts(:thinking)
+ post.people.build(first_name: "Bob")
+ ted = post.people.build(first_name: "Ted")
+ post.people.delete(ted)
+ post.save!
+ post.reload
+
+ assert_equal ["Bob"], post.people.collect(&:first_name)
+ end
+
def test_both_parent_ids_set_when_saving_new
post = Post.new(title: "Hello", body: "world")
person = Person.new(first_name: "Sean")