aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_mailroom/test_helper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-09-19 17:08:35 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2018-09-19 17:08:35 -0700
commita166c21a49ddb5e9cca7ecde7cbb671f14a56fef (patch)
tree2ea762de9d69dcf2e1dac751e6163fff1a3d5953 /lib/action_mailroom/test_helper.rb
parent8cd299286e9dd0c61731fe2d23f316c74d60b6bf (diff)
downloadrails-a166c21a49ddb5e9cca7ecde7cbb671f14a56fef.tar.gz
rails-a166c21a49ddb5e9cca7ecde7cbb671f14a56fef.tar.bz2
rails-a166c21a49ddb5e9cca7ecde7cbb671f14a56fef.zip
Allow inbound emails to be created on the fly
Diffstat (limited to 'lib/action_mailroom/test_helper.rb')
-rw-r--r--lib/action_mailroom/test_helper.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/action_mailroom/test_helper.rb b/lib/action_mailroom/test_helper.rb
index 06a38f75b6..7f56831f36 100644
--- a/lib/action_mailroom/test_helper.rb
+++ b/lib/action_mailroom/test_helper.rb
@@ -2,11 +2,17 @@ module ActionMailroom
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(fixture_name, status: :processing)
- raw_email = ActiveStorage::Blob.create_after_upload! \
- io: file_fixture(fixture_name).open, filename: fixture_name, content_type: 'message/rfc822'
-
- ActionMailroom::InboundEmail.create!(status: status, raw_email: raw_email)
+ def create_inbound_email_from_fixture(fixture_name, status: :processing)
+ create_inbound_email file_fixture(fixture_name).open, filename: fixture_name, status: status
end
+
+ def create_inbound_email_from_mail(status: :processing, &block)
+ create_inbound_email(StringIO.new(Mail.new { instance_eval(&block) }.to_s), status: status)
+ end
+
+ def create_inbound_email(io, filename: 'mail.eml', status: status)
+ ActionMailroom::InboundEmail.create! status: status, raw_email:
+ ActiveStorage::Blob.create_after_upload!(io: io, filename: filename, content_type: 'message/rfc822')
+ end
end
end