diff --git a/app/models/topic.rb b/app/models/topic.rb index 6192f727594..155736aa056 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -1103,14 +1103,13 @@ class Topic < ActiveRecord::Base topic_user = topic_allowed_users.find_by(user_id: user.id) if topic_user - topic_user.destroy - if user.id == removed_by&.id add_small_action(removed_by, "user_left", user.username) else add_small_action(removed_by, "removed_user", user.username) end + topic_user.destroy return true end end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 4db4f3a5546..9f8e466a7be 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -3081,6 +3081,17 @@ RSpec.describe Topic do describe "#remove_allowed_user" do fab!(:topic) { Fabricate(:topic) } + fab!(:private_topic) do + Fabricate( + :private_message_topic, + title: "Private message", + user: admin, + topic_allowed_users: [ + Fabricate.build(:topic_allowed_user, user: admin), + Fabricate.build(:topic_allowed_user, user: user1), + ], + ) + end describe "removing oneself" do it "should remove onself" do @@ -3095,6 +3106,12 @@ RSpec.describe Topic do expect(post.post_type).to eq(Post.types[:small_action]) expect(post.action_code).to eq("user_left") end + + it "should show a small action when user removes themselves from pm" do + expect do private_topic.remove_allowed_user(user1, user1) end.to change { + private_topic.posts.where(action_code: "user_left").count + }.by(1) + end end end