aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/persistence_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-05-11 19:40:26 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-05-11 19:57:22 +0900
commitab3ad6a9ad119825636153cd521e25c280483340 (patch)
treeef7e87a1e06d771f24d7eb714a9623dc36b6431a /activerecord/test/cases/persistence_test.rb
parent5ed8aa9e02014d7840e746f407068315d6fc6b63 (diff)
downloadrails-ab3ad6a9ad119825636153cd521e25c280483340.tar.gz
rails-ab3ad6a9ad119825636153cd521e25c280483340.tar.bz2
rails-ab3ad6a9ad119825636153cd521e25c280483340.zip
`becomes` should clear the mutation tracker which is created in `after_initialize`
`becomes` creates new object and copies attributes from the receiver. If new object has mutation tracker which is created in `after_initialize`, it should be cleared since it is for discarded attributes. But if the receiver doesn't have mutation tracker yet, it will not be cleared properly. It should be cleared regardless of whether the receiver has mutation tracker or not. Fixes #32867.
Diffstat (limited to 'activerecord/test/cases/persistence_test.rb')
-rw-r--r--activerecord/test/cases/persistence_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb
index e0c5725944..47e9683b44 100644
--- a/activerecord/test/cases/persistence_test.rb
+++ b/activerecord/test/cases/persistence_test.rb
@@ -290,6 +290,17 @@ class PersistenceTest < ActiveRecord::TestCase
assert_equal "The First Topic", Topic.find(copy.id).title
end
+ def test_becomes_wont_break_mutation_tracking
+ topic = topics(:first)
+ reply = topic.becomes(Reply)
+
+ assert_equal 1, topic.id_in_database
+ assert_empty topic.attributes_in_database
+
+ assert_equal 1, reply.id_in_database
+ assert_empty reply.attributes_in_database
+ end
+
def test_becomes_includes_changed_attributes
company = Company.new(name: "37signals")
client = company.becomes(Client)