Merge pull request #10675 from colinux/fix-contact-form-deletion

Tech: permet la suppression des ContactForm d'users ayant des dossiers
This commit is contained in:
Colin Darie 2024-08-01 19:51:48 +02:00 committed by GitHub
commit 9d1bc790cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 2 deletions

View file

@ -22,7 +22,7 @@ class HelpscoutCreateConversationJob < ApplicationJob
create_conversation
contact_form.destroy
contact_form.delete
end
private

View file

@ -1,7 +1,7 @@
class ContactForm < ApplicationRecord
attr_reader :options
belongs_to :user, optional: true, dependent: :destroy
belongs_to :user, optional: true
after_initialize :set_options
before_validation :normalize_strings

View file

@ -91,6 +91,21 @@ RSpec.describe HelpscoutCreateConversationJob, type: :job do
it 'associates the email from user' do
subject
expect(api).to have_received(:create_conversation).with(user.email, subject_text, text, nil)
expect(contact_form).to be_destroyed
expect(user.reload).to be_truthy
end
context 'having dossiers' do
before do
create(:dossier, user:)
end
it 'associates the email from user' do
subject
expect(api).to have_received(:create_conversation).with(user.email, subject_text, text, nil)
expect(contact_form).to be_destroyed
expect(user.reload).to be_truthy
end
end
end
end