Skip to content

Commit 4c3c409

Browse files
committed
Fix: options included in the headers
The call to `except` here should not be an array as there is no array of these symbol to exclude from the hash. This issue was kindly identified by @inulty-dfe in #162.
1 parent e5fc9b5 commit 4c3c409

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]
66

77
## [Unreleased]
88

9+
- Fixed a bug in `view_mail` and `template_mail` that meant the options were being
10+
included in the preview email headers for no reason - thanks to @inulty-dfe
11+
912
## [2.0.0] - 2024-04-01
1013

1114
- Version 2.0.0 rewrites most of the gem, without altering the API

lib/mail/notify/mailer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def template_mail(template_id, options)
3838

3939
message.personalisation = options[:personalisation] || {}
4040

41-
headers = options.except([:personalisation, :reply_to_id, :reference])
41+
headers = options.except(:personalisation, :reply_to_id, :reference)
4242

4343
headers[:subject] = "Subject managed in Notify" unless options[:subject]
4444

@@ -74,7 +74,7 @@ def view_mail(template_id, options)
7474
message.reference = options[:reference]
7575

7676
subject = options[:subject]
77-
headers = options.except([:personalisation, :reply_to_id, :reference])
77+
headers = options.except(:personalisation, :reply_to_id, :reference)
7878

7979
# we have to render the view for the message and grab the raw source, then we set that as the
8080
# body in the personalisation for sending to the Notify API.

spec/mail/notify/mailer_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@
115115
ArgumentError, "You must specify a subject"
116116
)
117117
end
118+
119+
it "does not include the personalisation, reply_to_id or reference options in the headers" do
120+
message_params = {
121+
template_id: "template-id",
122+
to: "test.name@email.co.uk",
123+
subject: "Test subject",
124+
personalisation: "test-personalisation",
125+
reply_to_id: "test@replyto.com",
126+
reference: "test-reference"
127+
}
128+
129+
message = TestMailer.with(message_params).test_view_mail
130+
131+
expect(message.header[:personalisation]).to be_nil
132+
expect(message.header[:reply_to_id]).to be_nil
133+
expect(message.header[:reference]).to be_nil
134+
end
118135
end
119136

120137
describe "#template_email" do
@@ -202,6 +219,23 @@
202219

203220
expect(message.reference).to eql("test-reference")
204221
end
222+
223+
it "does not include the personalisation, reply_to_id or reference options in the headers" do
224+
message_params = {
225+
template_id: "template-id",
226+
to: "test.name@email.co.uk",
227+
subject: "Test subject",
228+
personalisation: "test-personalisation",
229+
reply_to_id: "test@replyto.com",
230+
reference: "test-reference"
231+
}
232+
233+
message = TestMailer.with(message_params).test_template_mail
234+
235+
expect(message.header[:personalisation]).to be_nil
236+
expect(message.header[:reply_to_id]).to be_nil
237+
expect(message.header[:reference]).to be_nil
238+
end
205239
end
206240

207241
describe "#blank_allowed" do

0 commit comments

Comments
 (0)