Merge pull request #9221 from tchak/fix-dossier-mailer
ETQ Usager, je ne veux pas recevoir d'email si j'ai supprimé mon compte
This commit is contained in:
commit
7f0f7357fe
3 changed files with 15 additions and 13 deletions
|
@ -6,7 +6,7 @@ class DossierMailer < ApplicationMailer
|
||||||
|
|
||||||
layout 'mailers/layout'
|
layout 'mailers/layout'
|
||||||
default from: NO_REPLY_EMAIL
|
default from: NO_REPLY_EMAIL
|
||||||
after_action :prevent_perform_deliveries, only: [:notify_new_draft, :notify_new_answer]
|
after_action :prevent_perform_deliveries, only: [:notify_new_draft, :notify_new_answer, :notify_pending_correction]
|
||||||
|
|
||||||
def notify_new_draft
|
def notify_new_draft
|
||||||
@dossier = params[:dossier]
|
@dossier = params[:dossier]
|
||||||
|
@ -46,7 +46,9 @@ class DossierMailer < ApplicationMailer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_pending_correction(dossier)
|
def notify_pending_correction
|
||||||
|
commentaire = params[:commentaire]
|
||||||
|
dossier = commentaire.dossier
|
||||||
I18n.with_locale(dossier.user_locale) do
|
I18n.with_locale(dossier.user_locale) do
|
||||||
@dossier = dossier
|
@dossier = dossier
|
||||||
@service = dossier.procedure.service
|
@service = dossier.procedure.service
|
||||||
|
@ -183,7 +185,10 @@ class DossierMailer < ApplicationMailer
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def prevent_perform_deliveries
|
def prevent_perform_deliveries
|
||||||
if params[:commentaire]&.discarded? || params[:dossier]&.skip_user_notification_email?
|
commentaire = params[:commentaire]
|
||||||
|
dossier = commentaire&.dossier || params[:dossier]
|
||||||
|
|
||||||
|
if commentaire&.discarded? || dossier&.skip_user_notification_email?
|
||||||
mail.perform_deliveries = false
|
mail.perform_deliveries = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -114,7 +114,7 @@ class Commentaire < ApplicationRecord
|
||||||
|
|
||||||
def notify_user(job_options = {})
|
def notify_user(job_options = {})
|
||||||
if flagged_pending_correction?
|
if flagged_pending_correction?
|
||||||
DossierMailer.notify_pending_correction(dossier).deliver_later(job_options)
|
DossierMailer.with(commentaire: self).notify_pending_correction.deliver_later(job_options)
|
||||||
else
|
else
|
||||||
DossierMailer.with(commentaire: self).notify_new_answer.deliver_later(job_options)
|
DossierMailer.with(commentaire: self).notify_new_answer.deliver_later(job_options)
|
||||||
end
|
end
|
||||||
|
|
|
@ -509,23 +509,20 @@ describe Instructeurs::DossiersController, type: :controller do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in(instructeur.user)
|
sign_in(instructeur.user)
|
||||||
|
|
||||||
allow(DossierMailer).to receive(:notify_pending_correction)
|
|
||||||
.and_return(double(deliver_later: nil))
|
|
||||||
|
|
||||||
expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :messagerie)
|
expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :messagerie)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "dossier en instruction sends an email to user" do
|
||||||
|
let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure:) }
|
||||||
|
|
||||||
|
it { expect { subject }.to have_enqueued_mail(DossierMailer, :notify_pending_correction) }
|
||||||
|
end
|
||||||
|
|
||||||
context "dossier en instruction" do
|
context "dossier en instruction" do
|
||||||
let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure: procedure) }
|
let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure: procedure) }
|
||||||
|
|
||||||
before { subject }
|
before { subject }
|
||||||
|
|
||||||
it 'sends an email to user' do
|
|
||||||
expect(DossierMailer).to have_received(:notify_pending_correction).once
|
|
||||||
expect(DossierMailer).to have_received(:notify_pending_correction).with(dossier)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'pass en_construction and create a pending correction' do
|
it 'pass en_construction and create a pending correction' do
|
||||||
expect(response).to have_http_status(:ok)
|
expect(response).to have_http_status(:ok)
|
||||||
expect(response.body).to include('en attente de correction')
|
expect(response.body).to include('en attente de correction')
|
||||||
|
|
Loading…
Reference in a new issue