Skip to content

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

FIX: topic_tracking_state not erroring when missing user_stat (#14559)

Krzysztof Kotlarek0301b775a853
diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb
index 74d69c068f9..9bc7cf39401 100644
--- a/app/models/topic_tracking_state.rb
+++ b/app/models/topic_tracking_state.rb
@@ -171,7 +171,7 @@ class TopicTrackingState
category_id: post.topic.category_id,
notification_level: tu.notification_level,
archetype: post.topic.archetype,
- first_unread_at: tu.user.user_stat.first_unread_at,
+ first_unread_at: tu.user.user_stat&.first_unread_at,
unread_not_too_old: true
}
diff --git a/spec/models/topic_tracking_state_spec.rb b/spec/models/topic_tracking_state_spec.rb
index d795bb90f42..6f7cfd5e913 100644
--- a/spec/models/topic_tracking_state_spec.rb
+++ b/spec/models/topic_tracking_state_spec.rb
@@ -92,6 +92,17 @@ describe TopicTrackingState do
expect(data["payload"]["archetype"]).to eq(Archetype.default)
end
+ it "is not erroring when user_stat is missing" do
+ post.user.user_stat.destroy!
+ message = MessageBus.track_publish(described_class.unread_channel_key(post.user.id)) do
+ TopicTrackingState.publish_unread(post)
+ end.first
+
+ data = message.data
+
+ expect(message.user_ids).to contain_exactly(post.user.id)
+ end
+
it "does not publish whisper post to non-staff users" do
post.update!(post_type: Post.types[:whisper])