FIX: don't count whispers in user stats post_count

This commit is contained in:
Neil Lalonde 2017-11-02 16:08:42 -04:00
parent 24af9b7d97
commit f29290ad11
2 changed files with 24 additions and 15 deletions

View File

@ -473,7 +473,7 @@ class PostCreator
end
unless @post.topic.private_message?
@user.user_stat.post_count += 1
@user.user_stat.post_count += 1 if @post.post_type == Post.types[:regular]
@user.user_stat.topic_count += 1 if @post.is_first_post?
end

View File

@ -387,27 +387,34 @@ describe PostCreator do
it 'whispers do not mess up the public view' do
first = PostCreator.new(user,
topic_id: topic.id,
raw: 'this is the first post').create
topic_id: topic.id,
raw: 'this is the first post').create
user_stat = user.user_stat
whisper = PostCreator.new(user,
topic_id: topic.id,
reply_to_post_number: 1,
post_type: Post.types[:whisper],
raw: 'this is a whispered reply').create
topic_id: topic.id,
reply_to_post_number: 1,
post_type: Post.types[:whisper],
raw: 'this is a whispered reply').create
# don't count whispers in user stats
expect(user_stat.reload.post_count).to eq(1)
expect(whisper).to be_present
expect(whisper.post_type).to eq(Post.types[:whisper])
whisper_reply = PostCreator.new(user,
topic_id: topic.id,
reply_to_post_number: whisper.post_number,
post_type: Post.types[:regular],
raw: 'replying to a whisper this time').create
topic_id: topic.id,
reply_to_post_number: whisper.post_number,
post_type: Post.types[:regular],
raw: 'replying to a whisper this time').create
expect(whisper_reply).to be_present
expect(whisper_reply.post_type).to eq(Post.types[:whisper])
expect(user_stat.reload.post_count).to eq(1)
# date is not precise enough in db
whisper_reply.reload
@ -423,10 +430,12 @@ describe PostCreator do
expect(topic.posts_count).to eq(1)
expect(topic.highest_staff_post_number).to eq(3)
topic.update_columns(highest_staff_post_number: 0,
highest_post_number: 0,
posts_count: 0,
last_posted_at: 1.year.ago)
topic.update_columns(
highest_staff_post_number: 0,
highest_post_number: 0,
posts_count: 0,
last_posted_at: 1.year.ago
)
Topic.reset_highest(topic.id)