diff --git a/app/models/post.rb b/app/models/post.rb index 1b1766115..aa1e03f79 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -440,6 +440,11 @@ class Post < ActiveRecord::Base ) 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 before_create do diff --git a/spec/services/post_owner_changer_spec.rb b/spec/services/post_owner_changer_spec.rb index 7cd734829..6328fac29 100644 --- a/spec/services/post_owner_changer_spec.rb +++ b/spec/services/post_owner_changer_spec.rb @@ -21,8 +21,9 @@ describe PostOwnerChanger do it "changes the user" do 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 + expect(p1.topic.last_post_user_id).to eq(user_a.id) expect(old_user).not_to eq(p1.user) expect(p1.user).to eq(user_a) end