diff --git a/lib/action_mailbox/test_helper.rb b/lib/action_mailbox/test_helper.rb index 23b2bb02ca..680e8b43be 100644 --- a/lib/action_mailbox/test_helper.rb +++ b/lib/action_mailbox/test_helper.rb @@ -5,14 +5,15 @@ module ActionMailbox # 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).read, status: status + create_inbound_email_from_source file_fixture(fixture_name).read, status: status end def create_inbound_email_from_mail(status: :processing, **mail_options) - create_inbound_email Mail.new(mail_options).to_s, status: status + create_inbound_email_from_source Mail.new(mail_options).to_s, status: status end - def create_inbound_email(source, status: :processing) + # 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 @@ -23,5 +24,8 @@ module ActionMailbox def receive_inbound_email_from_mail(**kwargs) create_inbound_email_from_mail(**kwargs).tap(&:route) end + def receive_inbound_email_from_source(**kwargs) + create_inbound_email_from_source(**kwargs).tap(&:route) + end end end diff --git a/test/unit/inbound_email/message_id_test.rb b/test/unit/inbound_email/message_id_test.rb index c744a5bf99..1cc3de360e 100644 --- a/test/unit/inbound_email/message_id_test.rb +++ b/test/unit/inbound_email/message_id_test.rb @@ -7,7 +7,7 @@ class ActionMailbox::InboundEmail::MessageIdTest < ActiveSupport::TestCase end test "message id is generated if its missing" do - inbound_email = create_inbound_email "Date: Fri, 28 Sep 2018 11:08:55 -0700\r\nTo: a@example.com\r\nMime-Version: 1.0\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: 7bit\r\n\r\nHello!" + inbound_email = create_inbound_email_from_source "Date: Fri, 28 Sep 2018 11:08:55 -0700\r\nTo: a@example.com\r\nMime-Version: 1.0\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: 7bit\r\n\r\nHello!" assert_not_nil inbound_email.message_id end end