-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: view_mail does not duplicate headers
With a view mail we have to call `mail` twice, once to get the body of the email from the view and once again to override the format contents. We were passing in any custom headers for both calls which was resulting in duplicate headers in the message. By calling `mail` without the headers, we can get the body and not modify the headers, leaving that for the second call. Interestingly adding custom headers is pointless, as they will never end up in the email from Notify - we may want to stop messing with the headers at all - I think it is a hangover from the v1 implementation. This was kindly identified by @inulty-dfe in #162 who are testing the header Mail::Fields that are potentially duplicated.
- Loading branch information
Showing
3 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,20 @@ | |
expect(message.header[:reply_to_id]).to be_nil | ||
expect(message.header[:reference]).to be_nil | ||
end | ||
|
||
it "sets custom headers only once" do | ||
message_params = { | ||
template_id: "template-id", | ||
to: "[email protected]", | ||
subject: "Test subject", | ||
custom_header: "custom header value" | ||
} | ||
|
||
message = TestMailer.with(message_params).test_view_mail | ||
|
||
expect(message.header["custom-header"]).to be_a(Mail::Field) | ||
expect(message.header["custom-header"].value).to eq("custom header value") | ||
end | ||
end | ||
|
||
describe "#template_email" do | ||
|
@@ -236,6 +250,20 @@ | |
expect(message.header[:reply_to_id]).to be_nil | ||
expect(message.header[:reference]).to be_nil | ||
end | ||
|
||
it "sets custom headers only once" do | ||
message_params = { | ||
template_id: "template-id", | ||
to: "[email protected]", | ||
subject: "Test subject", | ||
custom_header: "custom header value" | ||
} | ||
|
||
message = TestMailer.with(message_params).test_view_mail | ||
|
||
expect(message.header["custom-header"]).to be_a(Mail::Field) | ||
expect(message.header["custom-header"].value).to eq("custom header value") | ||
end | ||
end | ||
|
||
describe "#blank_allowed" do | ||
|