From 4a11bb52277a661c9d82777d3090fd34546cbe06 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 15 Jan 2015 15:39:26 -0500 Subject: [PATCH] FIX: on topic page, don't try to render post counts for a deleted user --- lib/topic_view.rb | 1 + spec/components/topic_view_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lib/topic_view.rb b/lib/topic_view.rb index b10b2551e54..6a440eade50 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -212,6 +212,7 @@ class TopicView def post_counts_by_user @post_counts_by_user ||= Post.where(topic_id: @topic.id) + .where("user_id IS NOT NULL") .group(:user_id) .order("count_all DESC") .limit(24) diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb index d59de8da21c..c10fc0128a2 100644 --- a/spec/components/topic_view_spec.rb +++ b/spec/components/topic_view_spec.rb @@ -158,6 +158,12 @@ describe TopicView do it 'returns the two posters with their counts' do expect(topic_view.post_counts_by_user.to_a).to match_array([[first_poster.id, 2], [coding_horror.id, 1]]) end + + it "doesn't return counts for posts with authors who have been deleted" do + p2.user_id = nil + p2.save! + expect(topic_view.post_counts_by_user.to_a).to match_array([[first_poster.id, 2]]) + end end context '.participants' do