diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rb index 25e408b810d..76325cc9d1a 100644 --- a/app/serializers/topic_view_serializer.rb +++ b/app/serializers/topic_view_serializer.rb @@ -172,11 +172,11 @@ class TopicViewSerializer < ApplicationSerializer end def participants - object.posts_count.collect {|tuple| {user: object.participants[tuple.first], post_count: tuple[1]}} + object.post_counts_by_user.collect {|tuple| {user: object.participants[tuple.first], post_count: tuple[1]}} end def include_participants? - object.initial_load? && object.posts_count.present? + object.initial_load? && object.post_counts_by_user.present? end def suggested_topics diff --git a/lib/topic_view.rb b/lib/topic_view.rb index c6ef6e6c2a7..3a74d8d35a9 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -4,7 +4,11 @@ require_dependency 'summarize' class TopicView - attr_accessor :topic, :draft, :draft_key, :draft_sequence, :posts + attr_accessor :topic, + :draft, + :draft_key, + :draft_sequence, + :posts def initialize(topic_id, user=nil, options={}) @topic = find_topic(topic_id) @@ -169,14 +173,14 @@ class TopicView end end - def posts_count - @posts_count ||= Post.where(topic_id: @topic.id).group(:user_id).order('count_all desc').limit(24).count + def post_counts_by_user + @post_counts_by_user ||= Post.where(topic_id: @topic.id).group(:user_id).order('count_all desc').limit(24).count end def participants @participants ||= begin participants = {} - User.where(id: posts_count.map {|k,v| k}).each {|u| participants[u.id] = u} + User.where(id: post_counts_by_user.map {|k,v| k}).each {|u| participants[u.id] = u} participants end end diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb index b591c032378..dc200023adf 100644 --- a/spec/components/topic_view_spec.rb +++ b/spec/components/topic_view_spec.rb @@ -94,9 +94,9 @@ describe TopicView do end end - context '.posts_count' do + context '.post_counts_by_user' do it 'returns the two posters with their counts' do - topic_view.posts_count.to_a.should =~ [[first_poster.id, 2], [coding_horror.id, 1]] + topic_view.post_counts_by_user.to_a.should =~ [[first_poster.id, 2], [coding_horror.id, 1]] end end