diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 3440fd3f8..1df80c127 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -1,8 +1,7 @@ class NotificationMailer < ApplicationMailer default to: Proc.new { @user.email } - def send_dossier_received(dossier_id) - dossier = Dossier.find(dossier_id) + def send_dossier_received(dossier) send_notification(dossier, dossier.procedure.received_mail_template) end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 9452cc0eb..ef2351dd4 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -323,7 +323,7 @@ class Dossier < ApplicationRecord def send_dossier_received if saved_change_to_state? && en_instruction? - NotificationMailer.send_dossier_received(id).deliver_later + NotificationMailer.send_dossier_received(self).deliver_later end end diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index d60fb10a3..37a579fa7 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -38,7 +38,7 @@ RSpec.describe NotificationMailer, type: :mailer do end describe '.send_dossier_received' do - subject { described_class.send_dossier_received(dossier.id) } + subject { described_class.send_dossier_received(dossier) } let(:email_template) { create(:received_mail) } before do diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 09501c4d8..924aed3a5 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -603,7 +603,7 @@ describe Dossier do it "sends an email when the dossier becomes en_instruction" do dossier.en_instruction! - expect(NotificationMailer).to have_received(:send_dossier_received).with(dossier.id) + expect(NotificationMailer).to have_received(:send_dossier_received).with(dossier) end it "does not an email when the dossier becomes accepte" do