Permalink
Browse files

Add an integration spec file w/ mailgun records.

  • Loading branch information...
joshuap committed Dec 19, 2013
1 parent b55795a commit 4dbe69456b5718bc24464854cdad3411c71899cf
View
@@ -2,3 +2,4 @@
log/*.log
pkg/
tmp/
spec/fixtures/records/favicon.ico.env
View
@@ -111,7 +111,7 @@ def authenticate
# Returns Hash for Mail::Message#add_file
def attachment_from_params(uploaded_file_or_hash)
filename, content = if Hash === uploaded_file_or_hash
[uploaded_file_or_hash['filename'], uploaded_file_or_hash['tempfile'].read]
[uploaded_file_or_hash[:filename], uploaded_file_or_hash[:tempfile].read]
else
[uploaded_file_or_hash.original_filename, uploaded_file_or_hash.read]
end
View
@@ -0,0 +1 @@
hello world
View
@@ -0,0 +1 @@
hullo world
Binary file not shown.
Binary file not shown.
@@ -14,11 +14,8 @@
'attachment-count' => '2',
'attachment-1' => stub(:original_filename => 'foo.txt', :read => 'hello world'),
'attachment-2' => {
'filename' => 'bar.txt',
'type' => 'text/plain',
'name' => 'attachment-2',
'tempfile' => stub(:read => 'hullo world'),
'head' => "Content-Disposition: form-data; name=\"attachment-2\"; filename=\"bar.txt\"\r\nContent-Type: text/plain\r\nContent-Length: 11\r\n"
:filename => 'bar.txt',
:tempfile => stub(:read => 'hullo world')
}
}
@@ -12,11 +12,8 @@
'attachments' => '2',
'attachment1' => stub(:original_filename => 'hello.txt', :read => 'hello world'),
'attachment2' => {
'filename' => 'bar.txt',
'type' => 'text/plain',
'name' => 'attachment-2',
'tempfile' => stub(:read => 'hullo world'),
'head' => "Content-Disposition: form-data; name=\"attachment-2\"; filename=\"bar.txt\"\r\nContent-Type: text/plain\r\nContent-Length: ll\r\n"
:filename => 'bar.txt',
:tempfile => stub(:read => 'hullo world')
}
}
View
@@ -0,0 +1,14 @@
require 'spec_helper'
describe Incoming::Strategies::Mailgun do
let(:receiver) { test_receiver(:api_key => 'asdf') }
describe 'end-to-end' do
let(:request) { recorded_request('mailgun') }
before { OpenSSL::HMAC.stub(:hexdigest).and_return(request.params['signature']) }
it "receives the request" do
expect(receiver.receive(request)).to be_a Mail::Message
end
end
end
View
@@ -1,20 +1,33 @@
require 'rack'
FIXTURES_DIR = File.expand_path('../../spec/fixtures/records', __FILE__)
FIXTURES_DIR = File.expand_path('../../spec/fixtures', __FILE__)
class FixtureRecorder
def initialize(app)
@app = app
end
def call(env)
env['fixture_file_path'] = File.join(FIXTURES_DIR, [env['PATH_INFO'].downcase.gsub('/', '_')[/[^_].+/], 'env'].join('.'))
env['fixture_file_path'] = file_path_from(env)
@app.call(env)
ensure
File.open(env['fixture_file_path'], 'w') do |file|
file.write(Marshal.dump(env.merge({ 'rack.input' => env['rack.input'].read }).select { |key, value| Marshal.dump(value) rescue false }))
file.write(dump_env(env))
end
end
def file_path_from(env)
file_path = env['PATH_INFO'].downcase.gsub('/', '_')[/[^_].+[^_]/]
file_path = 'root' unless file_path =~ /\S/
File.join(FIXTURES_DIR, 'records', [file_path, 'env'].join('.'))
end
def dump_env(env)
safe_env = env.dup
safe_env.merge!({ 'rack.input' => env['rack.input'].read })
safe_env = safe_env.select { |key, value| Marshal.dump(value) rescue false }
Marshal.dump(safe_env)
end
end
app = Rack::Builder.new do

0 comments on commit 4dbe694

Please sign in to comment.