Skip to content

Commit

Permalink
Fix: options included in the headers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mec committed Oct 18, 2024
1 parent e5fc9b5 commit 2c88f41
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/mail/notify/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def template_mail(template_id, options)

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

headers = options.except([:personalisation, :reply_to_id, :reference])
headers = options.except(:personalisation, :reply_to_id, :reference)

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

Expand Down Expand Up @@ -74,7 +74,7 @@ def view_mail(template_id, options)
message.reference = options[:reference]

subject = options[:subject]
headers = options.except([:personalisation, :reply_to_id, :reference])
headers = options.except(:personalisation, :reply_to_id, :reference)

# we have to render the view for the message and grab the raw source, then we set that as the
# body in the personalisation for sending to the Notify API.
Expand Down
34 changes: 34 additions & 0 deletions spec/mail/notify/mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@
ArgumentError, "You must specify a subject"
)
end

it "does not include the personalisation, reply_to_id or reference options in the headers" do
message_params = {
template_id: "template-id",
to: "[email protected]",
subject: "Test subject",
personalisation: "test-personalisation",
reply_to_id: "[email protected]",
reference: "test-reference"
}

message = TestMailer.with(message_params).test_view_mail

expect(message.header[:personalisation]).to be_nil
expect(message.header[:reply_to_id]).to be_nil
expect(message.header[:reference]).to be_nil
end
end

describe "#template_email" do
Expand Down Expand Up @@ -202,6 +219,23 @@

expect(message.reference).to eql("test-reference")
end

it "does not include the personalisation, reply_to_id or reference options in the headers" do
message_params = {
template_id: "template-id",
to: "[email protected]",
subject: "Test subject",
personalisation: "test-personalisation",
reply_to_id: "[email protected]",
reference: "test-reference"
}

message = TestMailer.with(message_params).test_template_mail

expect(message.header[:personalisation]).to be_nil
expect(message.header[:reply_to_id]).to be_nil
expect(message.header[:reference]).to be_nil
end
end

describe "#blank_allowed" do
Expand Down

0 comments on commit 2c88f41

Please sign in to comment.