tags: fix post counts for nonexistent tags.

Fix a bug where the post count regenerator didn't fix counts for tags
that had a non-zero count but weren't present on any posts.
This commit is contained in:
evazion
2019-12-27 11:19:13 -06:00
parent b6a3a05422
commit 3b4f9ad086
2 changed files with 31 additions and 8 deletions

View File

@@ -278,11 +278,14 @@ class TagTest < ActiveSupport::TestCase
should "be fixed" do
tag1 = FactoryBot.create(:tag, name: "touhou", post_count: -10)
tag2 = FactoryBot.create(:tag, name: "bkub", post_count: 10)
tag3 = FactoryBot.create(:tag, name: "chen", post_count: 10)
post = FactoryBot.create(:post, tag_string: "touhou bkub")
Tag.regenerate_post_counts!
tags = Tag.regenerate_post_counts!
assert_equal(3, tags.size)
assert_equal(1, tag1.reload.post_count)
assert_equal(1, tag2.reload.post_count)
assert_equal(0, tag3.reload.post_count)
end
end
end