[#1972] Avoid passing unsaved templates to ActionMailer
So that all mail arguments can be serialized
This commit is contained in:
parent
1fb85afdc7
commit
cce00e19c6
9 changed files with 68 additions and 36 deletions
|
@ -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
|
||||
# We’re testing the (private) method `NotificationMailer#send_notification`.
|
||||
#
|
||||
# The standard trick to test a private method would be to `send(:send_notification`, but doesn’t 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) }
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue