Skip to content

Commit

Permalink
Merge pull request #7 from r38y/handle_empty_attachment_content
Browse files Browse the repository at this point in the history
Don't explode when handling attachments with no content.
  • Loading branch information
mmangino authored Mar 22, 2017
2 parents cbde1a6 636c25d commit 898d221
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/griddler/postmark/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 65,18 @@ def attachment_files
def create_tempfile(attachment)
filename = attachment[:Name].gsub(/\/|\\/, '_')
tempfile = Tempfile.new(filename, Dir::tmpdir, encoding: 'ascii-8bit')
tempfile.write(Base64.decode64(attachment[:Content]))
tempfile.write(content(attachment))
tempfile.rewind
tempfile
end

def content(attachment)
if content = attachment[:Content]
Base64.decode64(content)
else
content
end
end
end
end
end
13 changes: 13 additions & 0 deletions spec/griddler/postmark/adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 79,19 @@
})
end

it 'can handle a blank attachment content' do
params = default_params.merge({
Attachments: [
{
Name: "empty.gif",
}
]
})
expect {
Griddler::Postmark::Adapter.normalize_params(params)
}.to_not raise_error
end

def default_params
{
FromFull: {
Expand Down

0 comments on commit 898d221

Please sign in to comment.