From a57e2388f6c92b2f36f88a6177bf971e4b26a79d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 30 May 2018 23:55:34 +0200 Subject: [PATCH] =?UTF-8?q?Unify=20NotificationMailer=20methods=E2=80=99?= =?UTF-8?q?=20signatures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/mailers/notification_mailer.rb | 3 +-- app/models/dossier.rb | 2 +- spec/mailers/notification_mailer_spec.rb | 2 +- spec/models/dossier_spec.rb | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) 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