FIX: on topic page, don't try to render post counts for a deleted user

This commit is contained in:
Neil Lalonde 2015-01-15 15:39:26 -05:00
parent dc801bb442
commit 4a11bb5227
2 changed files with 7 additions and 0 deletions

View File

@ -212,6 +212,7 @@ class TopicView
def post_counts_by_user def post_counts_by_user
@post_counts_by_user ||= Post.where(topic_id: @topic.id) @post_counts_by_user ||= Post.where(topic_id: @topic.id)
.where("user_id IS NOT NULL")
.group(:user_id) .group(:user_id)
.order("count_all DESC") .order("count_all DESC")
.limit(24) .limit(24)

View File

@ -158,6 +158,12 @@ describe TopicView do
it 'returns the two posters with their counts' 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]]) expect(topic_view.post_counts_by_user.to_a).to match_array([[first_poster.id, 2], [coding_horror.id, 1]])
end 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 end
context '.participants' do context '.participants' do