FIX: post counts in user stats when changing post owner
This commit is contained in:
parent
21dd2ccd43
commit
18d65fe7e5
|
@ -290,9 +290,11 @@ class PostRevisor
|
||||||
private_message = @post.topic.private_message?
|
private_message = @post.topic.private_message?
|
||||||
|
|
||||||
prev_owner_user_stat = prev_owner.user_stat
|
prev_owner_user_stat = prev_owner.user_stat
|
||||||
prev_owner_user_stat.post_count -= 1
|
unless private_message
|
||||||
prev_owner_user_stat.topic_count -= 1 if @post.is_first_post?
|
prev_owner_user_stat.post_count -= 1 if @post.post_type == Post.types[:regular]
|
||||||
prev_owner_user_stat.likes_received -= likes if !private_message
|
prev_owner_user_stat.topic_count -= 1 if @post.is_first_post?
|
||||||
|
prev_owner_user_stat.likes_received -= likes
|
||||||
|
end
|
||||||
prev_owner_user_stat.update_topic_reply_count
|
prev_owner_user_stat.update_topic_reply_count
|
||||||
|
|
||||||
if @post.created_at == prev_owner.user_stat.first_post_created_at
|
if @post.created_at == prev_owner.user_stat.first_post_created_at
|
||||||
|
@ -302,9 +304,11 @@ class PostRevisor
|
||||||
prev_owner_user_stat.save!
|
prev_owner_user_stat.save!
|
||||||
|
|
||||||
new_owner_user_stat = new_owner.user_stat
|
new_owner_user_stat = new_owner.user_stat
|
||||||
new_owner_user_stat.post_count += 1
|
unless private_message
|
||||||
new_owner_user_stat.topic_count += 1 if @post.is_first_post?
|
new_owner_user_stat.post_count += 1 if @post.post_type == Post.types[:regular]
|
||||||
new_owner_user_stat.likes_received += likes if !private_message
|
new_owner_user_stat.topic_count += 1 if @post.is_first_post?
|
||||||
|
new_owner_user_stat.likes_received += likes
|
||||||
|
end
|
||||||
new_owner_user_stat.update_topic_reply_count
|
new_owner_user_stat.update_topic_reply_count
|
||||||
new_owner_user_stat.save!
|
new_owner_user_stat.save!
|
||||||
end
|
end
|
||||||
|
|
|
@ -131,19 +131,43 @@ describe PostOwnerChanger do
|
||||||
expect(user_a_stat.likes_received).to eq(1)
|
expect(user_a_stat.likes_received).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "handles whispers" do
|
||||||
|
whisper = PostCreator.new(
|
||||||
|
editor,
|
||||||
|
topic_id: p1.topic_id,
|
||||||
|
reply_to_post_number: 1,
|
||||||
|
post_type: Post.types[:whisper],
|
||||||
|
raw: 'this is a whispered reply'
|
||||||
|
).create
|
||||||
|
|
||||||
|
user_stat = editor.user_stat
|
||||||
|
|
||||||
|
expect {
|
||||||
|
described_class.new(
|
||||||
|
post_ids: [whisper.id],
|
||||||
|
topic_id: topic.id,
|
||||||
|
new_owner: Fabricate(:admin),
|
||||||
|
acting_user: editor
|
||||||
|
).change_owner!
|
||||||
|
}.to_not change { user_stat.reload.post_count }
|
||||||
|
end
|
||||||
|
|
||||||
context 'private message topic' do
|
context 'private message topic' do
|
||||||
let(:topic) { Fabricate(:private_message_topic) }
|
let(:topic) { Fabricate(:private_message_topic) }
|
||||||
|
|
||||||
it "should update users' counts" do
|
it "should update users' counts" do
|
||||||
PostAction.act(p2user, p1, PostActionType.types[:like])
|
PostAction.act(p2user, p1, PostActionType.types[:like])
|
||||||
|
|
||||||
change_owners
|
expect {
|
||||||
|
change_owners
|
||||||
|
}.to_not change { p1user.user_stat.post_count }
|
||||||
|
|
||||||
expect(p1user.user_stat.likes_received).to eq(0)
|
expect(p1user.user_stat.likes_received).to eq(0)
|
||||||
|
|
||||||
user_a_stat = user_a.user_stat
|
user_a_stat = user_a.user_stat
|
||||||
expect(user_a_stat.first_post_created_at).to be_present
|
expect(user_a_stat.first_post_created_at).to be_present
|
||||||
expect(user_a_stat.likes_received).to eq(0)
|
expect(user_a_stat.likes_received).to eq(0)
|
||||||
|
expect(user_a_stat.post_count).to eq(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue