Skip to content

A platform for community discussion. Free, open, simple.

FIX: Ignore posts needing approval when calculating reviewable counts. (#13464)

Roman Rizzie0e1e24c1472
diff --git a/lib/topic_view.rb b/lib/topic_view.rb
index 843e342163a..99efecfdb1e 100644
--- a/lib/topic_view.rb
+++ b/lib/topic_view.rb
@@ -509,7 +509,8 @@ class TopicView
reviewable_scores s ON reviewable_id = r.id
WHERE
r.target_id IN (:post_ids) AND
- r.target_type = 'Post'
+ r.target_type = 'Post' AND
+ COALESCE(s.reason, '') != 'category'
GROUP BY
target_id
SQL
diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb
index cfda8b6ef46..87385de49a7 100644
--- a/spec/components/topic_view_spec.rb
+++ b/spec/components/topic_view_spec.rb
@@ -915,4 +915,41 @@ describe TopicView do
expect(topic_view.show_read_indicator?).to be_falsey
end
end
+
+ describe '#reviewable_counts' do
+ it 'exclude posts queued because the category needs approval' do
+ category = Fabricate.build(:category, user: admin)
+ category.custom_fields[Category::REQUIRE_TOPIC_APPROVAL] = true
+ category.save!
+ manager = NewPostManager.new(
+ user,
+ raw: 'to the handler I say enqueue me!',
+ title: 'this is the title of the queued post',
+ category: category.id
+ )
+ result = manager.perform
+ reviewable = result.reviewable
+ reviewable.perform(admin, :approve_post)
+
+ topic_view = TopicView.new(reviewable.topic, admin)
+
+ expect(topic_view.reviewable_counts).to be_empty
+ end
+
+ it 'include posts queued for other reasons' do
+ Fabricate(:watched_word, word: "darn", action: WatchedWord.actions[:require_approval])
+ manager = NewPostManager.new(
+ user,
+ raw: 'this is darn new post content',
+ title: 'this is the title of the queued post'
+ )
+ result = manager.perform
+ reviewable = result.reviewable
+ reviewable.perform(admin, :approve_post)
+
+ topic_view = TopicView.new(reviewable.topic, admin)
+
+ expect(topic_view.reviewable_counts.keys).to contain_exactly(reviewable.target_id)
+ end
+ end
end