Fix: アカウント削除時エラーが出る問題

This commit is contained in:
KMY 2024-10-09 20:24:12 +09:00
parent 428abf33f2
commit aadde1bbaa
3 changed files with 8 additions and 0 deletions

View file

@ -19,6 +19,7 @@ module Account::Associations
has_many :conversations, class_name: 'AccountConversation', dependent: :destroy, inverse_of: :account has_many :conversations, class_name: 'AccountConversation', dependent: :destroy, inverse_of: :account
has_many :scheduled_statuses, inverse_of: :account, dependent: :destroy has_many :scheduled_statuses, inverse_of: :account, dependent: :destroy
has_many :scheduled_expiration_statuses, inverse_of: :account, dependent: :destroy has_many :scheduled_expiration_statuses, inverse_of: :account, dependent: :destroy
has_many :ng_rule_histories, inverse_of: :account, dependent: :destroy
# Notifications # Notifications
has_many :notifications, inverse_of: :account, dependent: :destroy has_many :notifications, inverse_of: :account, dependent: :destroy

View file

@ -102,6 +102,7 @@ class DeleteAccountService < BaseService
record_severed_relationships! record_severed_relationships!
distribute_activities! distribute_activities!
purge_content! purge_content!
remove_ng_rule_history_relations!
fulfill_deletion_request! fulfill_deletion_request!
end end
@ -273,6 +274,10 @@ class DeleteAccountService < BaseService
@account.save! @account.save!
end end
def remove_ng_rule_history_relations!
@account.ng_rule_histories.update_all(account_id: Account.representative.id)
end
def fulfill_deletion_request! def fulfill_deletion_request!
@account.deletion_request&.destroy @account.deletion_request&.destroy
end end

View file

@ -83,6 +83,8 @@ RSpec.describe DeleteAccountService do
expect { pending_follow_request.reload }.to raise_error(ActiveRecord::RecordNotFound) expect { pending_follow_request.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { pending_status.reload }.to raise_error(ActiveRecord::RecordNotFound) expect { pending_status.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { fetchable_pending_status.reload }.to raise_error(ActiveRecord::RecordNotFound) expect { fetchable_pending_status.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect(ng_rule_history.account_id).to eq Account.representative.id
end end
def expect_deletion_of_associated_owned_records def expect_deletion_of_associated_owned_records