FIX: when changing owner of last post user list on topic incorrect

This commit is contained in:
Sam Saffron 2016-03-16 23:49:27 +11:00
parent 49502f4601
commit b300d60086
2 changed files with 7 additions and 1 deletions

View file

@ -440,6 +440,11 @@ class Post < ActiveRecord::Base
) )
revise(actor, { raw: self.raw, user_id: new_user.id, edit_reason: edit_reason }) revise(actor, { raw: self.raw, user_id: new_user.id, edit_reason: edit_reason })
if post_number == topic.highest_post_number
topic.update_columns(last_post_user_id: new_user.id)
end
end end
before_create do before_create do

View file

@ -21,8 +21,9 @@ describe PostOwnerChanger do
it "changes the user" do it "changes the user" do
old_user = p1.user old_user = p1.user
described_class.new(post_ids: [p1.id], topic_id: topic.id, new_owner: user_a, acting_user: editor).change_owner! PostOwnerChanger.new(post_ids: [p1.id], topic_id: topic.id, new_owner: user_a, acting_user: editor).change_owner!
p1.reload p1.reload
expect(p1.topic.last_post_user_id).to eq(user_a.id)
expect(old_user).not_to eq(p1.user) expect(old_user).not_to eq(p1.user)
expect(p1.user).to eq(user_a) expect(p1.user).to eq(user_a)
end end