aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_mailbox/test_helper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-09-28 12:19:43 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2018-09-28 12:19:43 -0700
commit8a0a1034955544ee2e4c1f85317c0db84f3aa55b (patch)
tree1e00acdce252b2ce505ff2e8f9f5acd4ba19bbeb /lib/action_mailbox/test_helper.rb
parent5ad0813322820a6c42d7b3074531ac40108bfb69 (diff)
downloadrails-8a0a1034955544ee2e4c1f85317c0db84f3aa55b.tar.gz
rails-8a0a1034955544ee2e4c1f85317c0db84f3aa55b.tar.bz2
rails-8a0a1034955544ee2e4c1f85317c0db84f3aa55b.zip
ActionMailroom -> ActionMailbox
We didn't end up using the mailroom metaphor directly, so let's stick with a more conventional naming strategy.
Diffstat (limited to 'lib/action_mailbox/test_helper.rb')
-rw-r--r--lib/action_mailbox/test_helper.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/action_mailbox/test_helper.rb b/lib/action_mailbox/test_helper.rb
new file mode 100644
index 0000000000..65a15a1281
--- /dev/null
+++ b/lib/action_mailbox/test_helper.rb
@@ -0,0 +1,22 @@
+require "mail"
+
+module ActionMailbox
+ module TestHelper
+ # Create an InboundEmail record using an eml fixture in the format of message/rfc822
+ # 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
+
+ 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 }
+ create_inbound_email(raw_email, status: status)
+ end
+
+ def create_inbound_email(io, filename: 'mail.eml', status: :processing)
+ ActionMailbox::InboundEmail.create_and_extract_message_id! \
+ ActionDispatch::Http::UploadedFile.new(tempfile: io, filename: filename, type: 'message/rfc822'),
+ status: status
+ end
+ end
+end