From b300d60086b40c25e435403f48c12cea24b74773 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Wed, 16 Mar 2016 23:49:27 +1100 Subject: [PATCH] FIX: when changing owner of last post user list on topic incorrect --- app/models/post.rb | 5 +++++ spec/services/post_owner_changer_spec.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) 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