diff --git a/lib/phaxio/resources/webhook.rb b/lib/phaxio/resources/webhook.rb index a05c0ae..8762811 100644 --- a/lib/phaxio/resources/webhook.rb +++ b/lib/phaxio/resources/webhook.rb @@ -57,7 +57,9 @@ def files_to_array(files) end def generate_file_string(file) - file[:name] + DIGEST.hexdigest(file[:tempfile].read) + file_string = file[:name] + DIGEST.hexdigest(file[:tempfile].read) + file[:tempfile].rewind + file_string end end end diff --git a/spec/resources/webhook_spec.rb b/spec/resources/webhook_spec.rb index 80a71a2..5c18637 100644 --- a/spec/resources/webhook_spec.rb +++ b/spec/resources/webhook_spec.rb @@ -30,5 +30,39 @@ expect(result).to eq(false) end end + + context 'with files' do + let(:signature) { '1d2426c242a8c5de7eb1d9b662b7fda1d0b6edab' } + let(:params) { { test: true } } + + let(:file1) do + tempfile = Tempfile.new + tempfile.write("foo") + tempfile + end + + let(:file2) do + tempfile = Tempfile.new + tempfile.write("bar") + tempfile + end + + let(:files) do + [ + { name: 'file', tempfile: file1 }, + { name: 'file', tempfile: file2 } + ] + end + + it 'returns true' do + result = action + expect(result).to eq(true) + end + + it 'rewinds the files' do + action + expect(files.all? { |f| f[:tempfile].pos.zero? }).to eq(true) + end + end end end