From 636c25dfb6280d5f81d8dde609d2c0fc264d41b8 Mon Sep 17 00:00:00 2001 From: Randy Schmidt Date: Wed, 22 Mar 2017 15:40:14 -0400 Subject: [PATCH] Don't explode when handling attachments with no content. --- lib/griddler/postmark/adapter.rb | 10 +++++++++- spec/griddler/postmark/adapter_spec.rb | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/griddler/postmark/adapter.rb b/lib/griddler/postmark/adapter.rb index d0d67a9..e284d35 100644 --- a/lib/griddler/postmark/adapter.rb +++ b/lib/griddler/postmark/adapter.rb @@ -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 diff --git a/spec/griddler/postmark/adapter_spec.rb b/spec/griddler/postmark/adapter_spec.rb index 1531896..e819ddd 100644 --- a/spec/griddler/postmark/adapter_spec.rb +++ b/spec/griddler/postmark/adapter_spec.rb @@ -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: {