-
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.
We only keep a Mail::Message for use in previews, it is never actually sent, email sending is handled by Notify, not your application. The Notify API does not accept additional custom headers, so passing custom headers to the message via the call to `mail` serves no purpose as those headers will never be used (other than in the previews, where they get shown). This work refactors the two mailer methods so that only the `to` and `subject` headers are set on the Mail::Message returned.
- Loading branch information
Showing
2 changed files
with
35 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,7 +133,7 @@ | |
expect(message.header[:reference]).to be_nil | ||
end | ||
|
||
it "sets custom headers only once" do | ||
it "only includes to and subject headers" do | ||
message_params = { | ||
template_id: "template-id", | ||
to: "[email protected]", | ||
|
@@ -143,8 +143,8 @@ | |
|
||
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") | ||
expect(message.header["custom-header"]).to be_nil | ||
expect(message.header["template-id"]).to be_nil | ||
end | ||
end | ||
|
||
|
@@ -175,6 +175,21 @@ | |
expect(message.header[:subject].value).to eql("Subject managed in Notify") | ||
end | ||
|
||
context "when passed a subject" do | ||
it "uses that subject" do | ||
message_params = { | ||
template_id: "template-id", | ||
to: "[email protected]", | ||
subject: "Test subject" | ||
} | ||
|
||
message = TestMailer.with(message_params).test_template_mail | ||
|
||
expect(message.header[:subject]).to be_a Mail::Field | ||
expect(message.header[:subject].value).to eql("Test subject") | ||
end | ||
end | ||
|
||
it "sets the subject if one is passed, even though it will not be used" do | ||
message_params = {template_id: "template-id", to: "[email protected]", subject: "My subject"} | ||
|
||
|
@@ -251,7 +266,7 @@ | |
expect(message.header[:reference]).to be_nil | ||
end | ||
|
||
it "sets custom headers only once" do | ||
it "only includes to and subject headers" do | ||
message_params = { | ||
template_id: "template-id", | ||
to: "[email protected]", | ||
|
@@ -261,8 +276,7 @@ | |
|
||
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") | ||
expect(message.header["custom-header"]).to be_nil | ||
end | ||
end | ||
|
||
|