Clean up chat channels when deleting users (#6225)

This commit is contained in:
Michael Kohl 2020-02-21 21:59:23 +07:00 committed by GitHub
parent 207621f739
commit c9b641928f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -8,7 +8,7 @@ module Users
user.follows.delete_all
Follow.where(followable_id: user.id, followable_type: "User").delete_all
user.messages.delete_all
user.chat_channel_memberships.delete_all
Users::CleanupChatChannels.call(user)
user.mentions.delete_all
user.badge_achievements.delete_all
user.github_repos.delete_all

View file

@ -86,4 +86,20 @@ RSpec.describe Users::Delete, type: :service do
end
end
end
context "when cleaning up chat channels" do
let_it_be(:other_user) { create(:user) }
it "deletes the user's private chat channels" do
chat_channel = ChatChannel.create_with_users([user, other_user])
described_class.call(user)
expect(ChatChannel.find_by(id: chat_channel.id)).to be_nil
end
it "does not delete the user's open channels" do
chat_channel = ChatChannel.create_with_users([user, other_user], "open")
described_class.call(user)
expect(ChatChannel.find_by(id: chat_channel.id)).not_to be_nil
end
end
end