Skip to content

Commit

Permalink
Fix "invalid data format/type" error
Browse files Browse the repository at this point in the history
  • Loading branch information
norbertszivos committed Sep 22, 2017
1 parent b318bb7 commit 98e7c25
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/sparkpost_rails/delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def prepare_cc_headers_from mail, sparkpost_data
emails << copy[:address][:email]
end

@data[:content][:headers] = { cc: emails }
@data[:content][:headers] = { cc: emails.join(",") }
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/bcc_recipients_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}},
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]"]})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected]"})
end

it "handles name and email" do
Expand All @@ -82,7 +82,7 @@
a_hash_including({address: {email: "[email protected]", name: "Sam Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", name: "Brock Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]"]})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected]"})
end

it "handles mix of email only and name/email" do
Expand All @@ -95,7 +95,7 @@
{address: {email: "[email protected]", name: "Chris Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", name: "Brock Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected],[email protected]"})
end
end
end
Expand Down
20 changes: 10 additions & 10 deletions spec/cc_recipients_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]"]})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected]"})
end

it "handles name and email" do
Expand All @@ -23,7 +23,7 @@

expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]"]})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected]"})
end
end

Expand All @@ -35,7 +35,7 @@
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}},
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected],[email protected]"})
end

it "handles name and email" do
Expand All @@ -45,7 +45,7 @@
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", name: "Chris Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected],[email protected]"})
end

it "handles mix of email only and name/email" do
Expand All @@ -55,7 +55,7 @@
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected],[email protected]"})
end
end

Expand All @@ -67,7 +67,7 @@
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", header_to: anything}}),
a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]"]})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected]"})
end

it "handles name and email" do
Expand All @@ -77,7 +77,7 @@
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
a_hash_including({address: {email: "[email protected]", name: "Sam Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]"]})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected]"})
end
end

Expand All @@ -90,7 +90,7 @@
a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}},
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected],[email protected]"})
end

it "handles name and email" do
Expand All @@ -101,7 +101,7 @@
a_hash_including({address: {email: "[email protected]", name: "Sam Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", name: "Chris Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected],[email protected]"})
end

it "handles mix of email only and name/email for to recipients" do
Expand All @@ -112,7 +112,7 @@
a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}},
{address: {email: "[email protected]", name: "Chris Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected],[email protected]"})
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
test_email = Mailer.test_email cc: "Carl Test <[email protected]>", headers: {"Priority" => "urgent", "Sensitivity" => "private"}
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]"], "Priority" => "urgent", "Sensitivity" => "private"})
expect(@delivery_method.data[:content][:headers]).to eq({cc: "[email protected]", "Priority" => "urgent", "Sensitivity" => "private"})
end

it "does not pass inappropriate headers through to the API" do
Expand Down

0 comments on commit 98e7c25

Please sign in to comment.