From c2159ca0bff809f145658c474ffb18f7ef66dfb4 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Thu, 1 Aug 2024 19:33:57 +0200 Subject: [PATCH] fix(contact): allow deletion of contact form of users having dossiers --- app/jobs/helpscout_create_conversation_job.rb | 2 +- app/models/contact_form.rb | 2 +- .../helpscout_create_conversation_job_spec.rb | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/jobs/helpscout_create_conversation_job.rb b/app/jobs/helpscout_create_conversation_job.rb index a0f3801ea..675bfa23d 100644 --- a/app/jobs/helpscout_create_conversation_job.rb +++ b/app/jobs/helpscout_create_conversation_job.rb @@ -22,7 +22,7 @@ class HelpscoutCreateConversationJob < ApplicationJob create_conversation - contact_form.destroy + contact_form.delete end private diff --git a/app/models/contact_form.rb b/app/models/contact_form.rb index 4e518e598..f2b729ccd 100644 --- a/app/models/contact_form.rb +++ b/app/models/contact_form.rb @@ -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 diff --git a/spec/jobs/helpscout_create_conversation_job_spec.rb b/spec/jobs/helpscout_create_conversation_job_spec.rb index 054166703..c6149fcf4 100644 --- a/spec/jobs/helpscout_create_conversation_job_spec.rb +++ b/spec/jobs/helpscout_create_conversation_job_spec.rb @@ -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