fix(contact): allow deletion of contact form of users having dossiers

This commit is contained in:
Colin Darie 2024-08-01 19:33:57 +02:00
parent 3660e01d76
commit c2159ca0bf
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
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