aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/belongs_to_associations_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-05-27 01:40:00 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-05-27 02:33:47 +0900
commit6349ad300f2cace625b1c733410c4a39c91028ec (patch)
tree1146dfc488052e55fad9092da111a5e6070e3036 /activerecord/test/cases/associations/belongs_to_associations_test.rb
parentcbab69c2789ff49bd9e3580eba0ac273190c9dc7 (diff)
downloadrails-6349ad300f2cace625b1c733410c4a39c91028ec.tar.gz
rails-6349ad300f2cace625b1c733410c4a39c91028ec.tar.bz2
rails-6349ad300f2cace625b1c733410c4a39c91028ec.zip
Fix `belongs_to_counter_cache_after_update` to respect polymorphic type change
Diffstat (limited to 'activerecord/test/cases/associations/belongs_to_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb
index 856bc70f6b..6cbde2796a 100644
--- a/activerecord/test/cases/associations/belongs_to_associations_test.rb
+++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -1071,9 +1071,20 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
post = posts(:welcome)
comment = comments(:greetings)
- assert_difference lambda { post.reload.tags_count }, -1 do
+ assert_equal post.id, comment.id
+
+ assert_difference "post.reload.tags_count", -1 do
assert_difference "comment.reload.tags_count", +1 do
tagging.taggable = comment
+ tagging.save!
+ end
+ end
+
+ assert_difference "comment.reload.tags_count", -1 do
+ assert_difference "post.reload.tags_count", +1 do
+ tagging.taggable_type = post.class.polymorphic_name
+ tagging.taggable_id = post.id
+ tagging.save!
end
end
end