[#1972] Avoid passing unsaved templates to ActionMailer

So that all mail arguments can be serialized
This commit is contained in:
Frederic Merizen 2018-05-25 23:08:47 +02:00
parent 1fb85afdc7
commit cce00e19c6
9 changed files with 68 additions and 36 deletions

View file

@ -18,7 +18,19 @@ RSpec.describe NotificationMailer, type: :mailer do
describe '.send_notification' do
let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') }
subject { described_class.send_notification(dossier, email_template) }
subject do
klass = Class.new(described_class) do
# Were testing the (private) method `NotificationMailer#send_notification`.
#
# The standard trick to test a private method would be to `send(:send_notification`, but doesnt work here,
# because ActionMailer does some magic to expose public instace methods as class methods.
# So, we use inheritance instead to make the private method public for testing purposes.
def send_notification(dossier, template)
super
end
end
klass.send_notification(dossier, email_template)
end
it { expect(subject.subject).to eq(email_template.subject_for_dossier) }
it { expect(subject.body).to eq(email_template.body_for_dossier) }

View file

@ -1,6 +1,6 @@
class NotificationMailerPreview < ActionMailer::Preview
def send_notification
NotificationMailer.send_notification(Dossier.last, Dossier.last.procedure.initiated_mail_template)
NotificationMailer.send_initiated_notification(Dossier.last)
end
def send_draft_notification