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

publish_unread should not error when UserStat is missing
This commit is contained in:
Krzysztof Kotlarek 2021-10-11 13:20:55 +11:00 committed by GitHub
parent 2944d2cdd6
commit 0301b775a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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
}

View File

@ -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])