aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/autosave_association_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-04-18 10:44:26 -0400
committerSean Griffin <sean@thoughtbot.com>2015-04-18 10:47:04 -0400
commitd849f42b4ecf687ed5350f5a2402fb795aa33aac (patch)
tree1b65d8e0df921dc78693120c80d609d53c4fc100 /activerecord/test/cases/autosave_association_test.rb
parent228559eab8e50dd52e1f07841a288ed39c84ff4e (diff)
downloadrails-d849f42b4ecf687ed5350f5a2402fb795aa33aac.tar.gz
rails-d849f42b4ecf687ed5350f5a2402fb795aa33aac.tar.bz2
rails-d849f42b4ecf687ed5350f5a2402fb795aa33aac.zip
Autosave existing records on HMT associations when the parent is new
To me it seems like this should only be the case if `autosave: true` is set on the association. However, when implemented that way, it caused issues with has many associations, where we have explicit tests stating that child records are updated when the parent is new, even if autosave is not set (presumably to update the parent id, but other changed attributes would be persisted as well). It's quirky, but at least we should be consistently quirky. This constitutes a minor but subtle change in behavior, and therefore should not be backported to 4.2 and earlier. Fixes #19782
Diffstat (limited to 'activerecord/test/cases/autosave_association_test.rb')
-rw-r--r--activerecord/test/cases/autosave_association_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb
index 8f0d7bd037..0e6f38cad6 100644
--- a/activerecord/test/cases/autosave_association_test.rb
+++ b/activerecord/test/cases/autosave_association_test.rb
@@ -1278,6 +1278,16 @@ module AutosaveAssociationOnACollectionAssociationTests
assert_equal new_names, @pirate.reload.send(@association_name).map(&:name)
end
+ def test_should_update_children_when_autosave_is_true_and_parent_is_new_but_child_is_not
+ parrot = Parrot.create!(name: "Polly")
+ parrot.name = "Squawky"
+ pirate = Pirate.new(parrots: [parrot], catchphrase: "Arrrr")
+
+ pirate.save!
+
+ assert_equal "Squawky", parrot.reload.name
+ end
+
def test_should_automatically_validate_the_associated_models
@pirate.send(@association_name).each { |child| child.name = '' }