Rename `posts_count` in topic view to `post_counts_by_user` which makes much more sense

This commit is contained in:
Robin Ward 2013-03-26 14:06:24 -04:00
parent 2efd3e61c7
commit 5dc47c2d82
3 changed files with 12 additions and 8 deletions

View File

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

View File

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

View File

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