aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailbox/lib/action_mailbox/test_helper.rb
diff options
context:
space:
mode:
authorGeorge Claghorn <george.claghorn@gmail.com>2018-12-26 11:02:59 -0500
committerGitHub <noreply@github.com>2018-12-26 11:02:59 -0500
commit9b35b9ff417e8ec9888deac1e66c2855677164cd (patch)
tree82dc9a20a23b855f91f743c5029ec7a97a35b824 /actionmailbox/lib/action_mailbox/test_helper.rb
parentb5ed468492387d42a44ca6af525d4a274cda756d (diff)
parenta5b2fff64ca0c1fa7be5124f40a251d991c10a85 (diff)
downloadrails-9b35b9ff417e8ec9888deac1e66c2855677164cd.tar.gz
rails-9b35b9ff417e8ec9888deac1e66c2855677164cd.tar.bz2
rails-9b35b9ff417e8ec9888deac1e66c2855677164cd.zip
Merge pull request #34786 from georgeclaghorn/actionmailbox
Import Action Mailbox
Diffstat (limited to 'actionmailbox/lib/action_mailbox/test_helper.rb')
-rw-r--r--actionmailbox/lib/action_mailbox/test_helper.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/actionmailbox/lib/action_mailbox/test_helper.rb b/actionmailbox/lib/action_mailbox/test_helper.rb
new file mode 100644
index 0000000000..02c52fb779
--- /dev/null
+++ b/actionmailbox/lib/action_mailbox/test_helper.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+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_from_source file_fixture(fixture_name).read, status: status
+ end
+
+ # Create an `InboundEmail` by specifying it using `Mail.new` options. Example:
+ #
+ # create_inbound_email_from_mail(from: "david@loudthinking.com", subject: "Hello!")
+ def create_inbound_email_from_mail(status: :processing, **mail_options)
+ create_inbound_email_from_source Mail.new(mail_options).to_s, status: status
+ end
+
+ # Create an `InboundEmail` using the raw rfc822 `source` as text.
+ def create_inbound_email_from_source(source, status: :processing)
+ ActionMailbox::InboundEmail.create_and_extract_message_id! source, status: status
+ end
+
+
+ # Create an `InboundEmail` from fixture using the same arguments as `create_inbound_email_from_fixture`
+ # and immediately route it to processing.
+ def receive_inbound_email_from_fixture(*args)
+ create_inbound_email_from_fixture(*args).tap(&:route)
+ end
+
+ # Create an `InboundEmail` from fixture using the same arguments as `create_inbound_email_from_mail`
+ # and immediately route it to processing.
+ def receive_inbound_email_from_mail(**kwargs)
+ create_inbound_email_from_mail(**kwargs).tap(&:route)
+ end
+
+ # Create an `InboundEmail` from fixture using the same arguments as `create_inbound_email_from_source`
+ # and immediately route it to processing.
+ def receive_inbound_email_from_source(**kwargs)
+ create_inbound_email_from_source(**kwargs).tap(&:route)
+ end
+ end
+end