Skip to content

Commit

Permalink
Merge pull request #91 from wildbit/fix-message-stream-headers
Browse files Browse the repository at this point in the history
Set the message stream as a header so we pass it to the API properly
  • Loading branch information
Nick Hammond authored Sep 9, 2020
2 parents b1d765e + 4320803 commit 013898d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
8 changes: 6 additions & 2 deletions lib/postmark/message_extensions/mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ def template_model(model = nil)
@template_model = model
end

attr_writer :message_stream
def message_stream(val = nil)
self.message_stream = val unless val.nil?
@message_stream
header['MESSAGE-STREAM'].to_s
end

def message_stream=(val)
header['MESSAGE-STREAM'] = val
end

def templated?
Expand Down Expand Up @@ -188,6 +191,7 @@ def reserved_headers
attachment to
track-opens track-links
postmark-template-alias
message-stream
]
end

Expand Down
8 changes: 4 additions & 4 deletions spec/unit/postmark/api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1086,10 +1086,10 @@
specify do
expect(http_client).to receive(:post).
with('message-streams',
match_json({
:Name => 'My Stream',
:Id => 'my-stream',
:MessageStreamType => 'Broadcasts'
json_representation_of({
'Name' => 'My Stream',
'Id' => 'my-stream',
'MessageStreamType' => 'Broadcasts'
}))
subject
end
Expand Down
38 changes: 21 additions & 17 deletions spec/unit/postmark/mail_message_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@
end

it 'converts plain text messages correctly' do
expect(subject.new(mail_message).run).to eq ({
expect(subject.new(mail_message).run).to eq({
"From" => "[email protected]",
"Subject" => "Hello!",
"TextBody" => "Hello Sheldon!",
"To" => "[email protected]"})
end

it 'converts tagged text messages correctly' do
expect(subject.new(tagged_mail_message).run).to eq ({
expect(subject.new(tagged_mail_message).run).to eq({
"From" => "[email protected]",
"Subject" => "Hello!",
"TextBody" => "Hello Sheldon!",
Expand All @@ -190,22 +190,22 @@
end

it 'converts plain text messages without body correctly' do
expect(subject.new(mail_message_without_body).run).to eq ({
expect(subject.new(mail_message_without_body).run).to eq({
"From" => "[email protected]",
"Subject" => "Hello!",
"To" => "[email protected]"})
end

it 'converts html messages correctly' do
expect(subject.new(mail_html_message).run).to eq ({
expect(subject.new(mail_html_message).run).to eq({
"From" => "[email protected]",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
"To" => "[email protected]"})
end

it 'converts multipart messages correctly' do
expect(subject.new(mail_multipart_message).run).to eq ({
expect(subject.new(mail_multipart_message).run).to eq({
"From" => "[email protected]",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
Expand All @@ -214,7 +214,7 @@
end

it 'converts messages with attachments correctly' do
expect(subject.new(mail_message_with_attachment).run).to eq ({
expect(subject.new(mail_message_with_attachment).run).to eq({
"From" => "[email protected]",
"Subject" => "Hello!",
"Attachments" => [{"Name" => "empty.gif",
Expand All @@ -225,7 +225,7 @@
end

it 'converts messages with named addresses correctly' do
expect(subject.new(mail_message_with_named_addresses).run).to eq ({
expect(subject.new(mail_message_with_named_addresses).run).to eq({
"From" => "Sheldon <[email protected]>",
"Subject" => "Hello!",
"TextBody" => "Hello Sheldon!",
Expand All @@ -244,7 +244,7 @@
context 'open tracking' do
context 'setup inside of mail' do
it 'converts open tracking enabled messages correctly' do
expect(subject.new(mail_message_with_open_tracking).run).to eq ({
expect(subject.new(mail_message_with_open_tracking).run).to eq({
"From" => "[email protected]",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
Expand All @@ -253,7 +253,7 @@
end

it 'converts open tracking disabled messages correctly' do
expect(subject.new(mail_message_with_open_tracking_disabled).run).to eq ({
expect(subject.new(mail_message_with_open_tracking_disabled).run).to eq({
"From" => "[email protected]",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
Expand All @@ -264,7 +264,7 @@

context 'setup with tracking variable' do
it 'converts open tracking enabled messages correctly' do
expect(subject.new(mail_message_with_open_tracking_set_variable).run).to eq ({
expect(subject.new(mail_message_with_open_tracking_set_variable).run).to eq({
"From" => "[email protected]",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
Expand All @@ -273,7 +273,7 @@
end

it 'converts open tracking disabled messages correctly' do
expect(subject.new(mail_message_with_open_tracking_disabled_set_variable).run).to eq ({
expect(subject.new(mail_message_with_open_tracking_disabled_set_variable).run).to eq({
"From" => "[email protected]",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
Expand All @@ -285,7 +285,7 @@

context 'link tracking' do
it 'converts html and text link tracking enabled messages correctly' do
expect(subject.new(mail_message_with_link_tracking_all).run).to eq ({
expect(subject.new(mail_message_with_link_tracking_all).run).to eq({
"From" => "[email protected]",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
Expand All @@ -294,7 +294,7 @@
end

it 'converts html only link tracking enabled messages correctly' do
expect(subject.new(mail_message_with_link_tracking_html).run).to eq ({
expect(subject.new(mail_message_with_link_tracking_html).run).to eq({
"From" => "[email protected]",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
Expand All @@ -303,7 +303,7 @@
end

it 'converts text only link tracking enabled messages correctly' do
expect(subject.new(mail_message_with_link_tracking_text).run).to eq ({
expect(subject.new(mail_message_with_link_tracking_text).run).to eq({
"From" => "[email protected]",
"Subject" => "Hello!",
"HtmlBody" => "<b>Hello Sheldon!</b>",
Expand Down Expand Up @@ -377,13 +377,17 @@

describe 'passing message stream' do
context 'when not set' do
specify { expect(mail_message.to_postmark_hash.keys).not_to include('MessageStream') }
specify { expect(subject.new(mail_message).run).not_to include('MessageStream') }
end

context 'when set' do
before { mail_message.message_stream = 'weekly-newsletter' }
before do
mail_message.message_stream = 'weekly-newsletter'
end

specify { expect(mail_message.to_postmark_hash).to include('MessageStream' => 'weekly-newsletter') }
it 'passes message stream to the API call' do
expect(subject.new(mail_message).run).to include('MessageStream' => 'weekly-newsletter')
end
end
end
end

0 comments on commit 013898d

Please sign in to comment.