Skip to content

Commit

Permalink
Default template model should be struct not array
Browse files Browse the repository at this point in the history
Postmark returns an error if an array is sent as the template model.
Empty struct works fine. This was causing the following error when
calling `PostmarkHelper.template` with no model :

`{"ErrorCode":403,"Message":"Received valid, but incompatible JSON
input."}`
  • Loading branch information
john-griffin authored and pablo-co committed Jan 17, 2018
1 parent 75d4783 commit a44d47d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/bamboo/postmark_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ defmodule Bamboo.PostmarkHelper do
Setup Postmark to send emails using a template. Use this in conjuction with
the template content to offload template rendering to Postmark. The
template id specified here must match the template id in Postmark.
Postmarks's API docs for this can be found [here](https://www.mandrillapp.com/api/docs/messages.JSON.html#method=send-template).
Postmarks's API docs for this can be found [here](https://postmarkapp.com/developer/api/templates-api#email-with-template).
## Example
template(email, "9746128")
template(email, "9746128", %{"name" => "Name", "content" => "John"})
"""
def template(email, template_id, template_model \\ []) do
def template(email, template_id, template_model \\ %{}) do
email
|> Email.put_private(:template_id, template_id)
|> Email.put_private(:template_model, template_model)
Expand Down
2 changes: 1 addition & 1 deletion test/lib/bamboo/postmark_adapter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ defmodule Bamboo.PostmarkAdapterTest do
assert_receive {:fake_postmark, %{params: %{"TemplateId" => template_id,
"TemplateModel" => template_model}}}
assert template_id == "hello"
assert template_model == []
assert template_model == %{}
end

test "deliver/2 puts template name and content" do
Expand Down

0 comments on commit a44d47d

Please sign in to comment.