1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add a test helper for creating and routing an inbound email

This commit is contained in:
George Claghorn 2018-10-01 15:42:32 -04:00
parent dd593b98b5
commit 704179251f
3 changed files with 10 additions and 2 deletions

View file

@ -2,6 +2,6 @@ class ActionMailbox::RoutingJob < ActiveJob::Base
queue_as :action_mailbox_routing
def perform(inbound_email)
ApplicationMailbox.route inbound_email
inbound_email.route
end
end

View file

@ -8,4 +8,8 @@ module ActionMailbox::InboundEmail::Routable
def route_later
ActionMailbox::RoutingJob.perform_later self
end
def route
ApplicationMailbox.route self
end
end

View file

@ -6,7 +6,7 @@ module ActionMailbox
# referenced with +fixture_name+ located in +test/fixtures/files/fixture_name+.
def create_inbound_email_from_fixture(fixture_name, status: :processing)
create_inbound_email file_fixture(fixture_name), filename: fixture_name, status: status
end
end
def create_inbound_email_from_mail(status: :processing, **mail_options)
raw_email = Tempfile.new.tap { |raw_email| raw_email.write Mail.new(mail_options).to_s }
@ -18,5 +18,9 @@ module ActionMailbox
ActionDispatch::Http::UploadedFile.new(tempfile: io, filename: filename, type: 'message/rfc822'),
status: status
end
def receive_inbound_email_from_mail(**kwargs)
create_inbound_email_from_mail(**kwargs).tap(&:route)
end
end
end