Skip to content

Commit

Permalink
Merge pull request #178 from sitaramshelke/customarg-use-string-key-v…
Browse files Browse the repository at this point in the history
…alues

Convert key/value arguments to CustomArgs to strings
  • Loading branch information
thinkingserious authored Oct 31, 2017
2 parents 0ee1850 + 772800a commit 37fc262
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sendgrid/helpers/mail/custom_arg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module SendGrid
class CustomArg
def initialize(key: nil, value: nil)
@custom_arg = {}
(key.nil? || value.nil?) ? @custom_arg = nil : @custom_arg[key] = value
(key.nil? || value.nil?) ? @custom_arg = nil : @custom_arg[key.to_s] = value.to_s
end

def custom_arg=(custom_arg)
Expand Down
15 changes: 15 additions & 0 deletions test/sendgrid/helpers/mail/test_mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ def test_add_custom_arg
assert_equal mail.to_json, expected_json
end

def test_add_non_string_custom_arg
mail = Mail.new
mail.add_custom_arg(CustomArg.new(key: "Integer", value: 1))
mail.add_custom_arg(CustomArg.new(key: "Array", value: [1, "a", true]))
mail.add_custom_arg(CustomArg.new(key: "Hash", value: {"a" => 1, "b" => 2}))
expected_json = {
"custom_args"=>{
"Integer"=>"1",
"Array"=>"[1, \"a\", true]",
"Hash"=>"{\"a\"=>1, \"b\"=>2}",
}
}
assert_equal mail.to_json, expected_json
end

def test_add_attachment
mail = Mail.new
mail.add_attachment('foo')
Expand Down

0 comments on commit 37fc262

Please sign in to comment.