refactor(mail.delay): use simplier implementation using after_action to prevent email delivery with delay

This commit is contained in:
Martin 2021-11-16 15:12:05 +01:00
parent e48b6e0c1f
commit 8bbd77f89f
6 changed files with 29 additions and 48 deletions

View file

@ -28,8 +28,8 @@ RSpec.describe DossierMailer, type: :mailer do
describe '.notify_new_answer with dossier brouillon' do
let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) }
subject { described_class.notify_new_answer(dossier) }
let(:commentaire) { create(:commentaire, dossier: dossier) }
subject { described_class.with(commentaire: commentaire).notify_new_answer }
it { expect(subject.subject).to include("Nouveau message") }
it { expect(subject.subject).to include(dossier.id.to_s) }
@ -40,8 +40,8 @@ RSpec.describe DossierMailer, type: :mailer do
describe '.notify_new_answer with dossier en construction' do
let(:dossier) { create(:dossier, state: "en_construction", procedure: build(:simple_procedure)) }
subject { described_class.notify_new_answer(dossier) }
let(:commentaire) { create(:commentaire, dossier: dossier) }
subject { described_class.with(commentaire: commentaire).notify_new_answer }
it { expect(subject.subject).to include("Nouveau message") }
it { expect(subject.subject).to include(dossier.id.to_s) }
@ -50,6 +50,15 @@ RSpec.describe DossierMailer, type: :mailer do
it_behaves_like 'a dossier notification'
end
describe '.notify_new_answer with commentaire discarded' do
let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) }
let(:commentaire) { create(:commentaire, dossier: dossier, discarded_at: 2.minutes.ago) }
subject { described_class.with(commentaire: commentaire).notify_new_answer }
it { expect(subject.perform_deliveries).to be_falsy }
end
describe '.notify_deletion_to_user' do
let(:deleted_dossier) { build(:deleted_dossier) }