FIX: No small action created when a non-author removes itself from a PM (#20502)

Fixes a small issue where allowed user removes themselves from a private message before the post activity (small action) is created.

I also added some test coverage to prevent regression.

/t/92811
This commit is contained in:
David Battersby
2023-03-02 13:47:54 +08:00
committed by GitHub
parent 607c123d90
commit 96d03ea9c0
2 changed files with 18 additions and 2 deletions

View File

@ -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