mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 16:29:52 +01:00
fix deletion of inbox entries when deleting an user
This commit is contained in:
parent
b8fd519e2d
commit
dc41f15097
2 changed files with 28 additions and 1 deletions
|
@ -22,7 +22,8 @@ class Inbox < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
after_destroy do
|
after_destroy do
|
||||||
user.touch(:inbox_updated_at)
|
# user might not exist at this point (account deleted, records are cleaned up async)
|
||||||
|
user&.touch(:inbox_updated_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
def answer(answer_content, user)
|
def answer(answer_content, user)
|
||||||
|
|
26
spec/models/inbox_spec.rb
Normal file
26
spec/models/inbox_spec.rb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Inbox, type: :model do
|
||||||
|
describe "associations" do
|
||||||
|
it { should belong_to(:user) }
|
||||||
|
it { should belong_to(:question) }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "before_destroy" do
|
||||||
|
let(:user) { FactoryBot.create(:user) }
|
||||||
|
let(:question) { FactoryBot.create(:question, author_is_anonymous: true) }
|
||||||
|
|
||||||
|
it "does not fail if the user wants to delete their account" do
|
||||||
|
Inbox.create(user:, question:)
|
||||||
|
|
||||||
|
# this deletes the User record and enqueues the deletion of all
|
||||||
|
# associated records in sidekiq
|
||||||
|
user.destroy!
|
||||||
|
|
||||||
|
# so let's drain the queues
|
||||||
|
expect { Sidekiq::Worker.drain_all }.not_to raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue