From 9a60c835358d10411d4c1ea02edb005289d88994 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Thu, 12 Aug 2021 10:31:50 +0800 Subject: [PATCH] FIX: `TopicTrackingState.report` not including unread for staff posts. Follow-up to e15c86e8c5ff9fcb8aec32d3bab641c2ab4193a9 --- app/models/topic_tracking_state.rb | 2 +- spec/models/topic_tracking_state_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb index e5ea071b426..e7db1b888e8 100644 --- a/app/models/topic_tracking_state.rb +++ b/app/models/topic_tracking_state.rb @@ -385,7 +385,7 @@ class TopicTrackingState if skip_unread "1=0" else - unread_filter_sql + unread_filter_sql(staff: staff) end filter_old_unread_sql = diff --git a/spec/models/topic_tracking_state_spec.rb b/spec/models/topic_tracking_state_spec.rb index 85133188c37..e25df41d22a 100644 --- a/spec/models/topic_tracking_state_spec.rb +++ b/spec/models/topic_tracking_state_spec.rb @@ -688,4 +688,27 @@ describe TopicTrackingState do expect(TopicTrackingState.report(post.user)).to be_empty expect(TopicTrackingState.report(user)).to be_empty end + + describe ".report" do + it "correctly reports topics with staff posts" do + create_post( + raw: "this is a test post", + topic: topic, + user: post.user + ) + + create_post( + raw: "this is a test post", + topic: topic, + post_type: Post.types[:whisper], + user: user + ) + + post.user.grant_admin! + + state = TopicTrackingState.report(post.user) + + expect(state.map(&:topic_id)).to contain_exactly(topic.id) + end + end end