Delete classified listings when deleting user (#6258)

This commit is contained in:
Michael Kohl 2020-02-27 02:44:09 +07:00 committed by GitHub
parent ac58bbeeb9
commit ec8ee54559
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions

View file

@ -46,7 +46,7 @@ class User < ApplicationRecord
has_many :html_variants, dependent: :destroy
has_many :page_views, dependent: :destroy
has_many :credits, dependent: :destroy
has_many :classified_listings
has_many :classified_listings, dependent: :destroy
has_many :poll_votes, dependent: :destroy
has_many :poll_skips, dependent: :destroy
has_many :backup_data, foreign_key: "instance_user_id", inverse_of: :instance_user, class_name: "BackupData", dependent: :delete_all

View file

@ -35,6 +35,7 @@ module Users
user.profile_pins.delete_all
user.rating_votes.delete_all
user.tweets.delete_all
user.classified_listings.delete_all
handle_feedback_messages(user)
end

View file

@ -236,6 +236,12 @@ RSpec.describe "Internal::Users", type: :request do
expect(user.follows.count).to eq(0)
end
it "removes a user's classified listings" do
create(:classified_listing, user: user)
banish_user
expect(user.classified_listings.count).to eq(0)
end
it "creates an entry in the BanishedUsers table" do
expect do
banish_user