mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow inbound emails to be created on the fly
This commit is contained in:
parent
8cd299286e
commit
a166c21a49
6 changed files with 22 additions and 12 deletions
|
@ -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'
|
||||
def create_inbound_email_from_fixture(fixture_name, status: :processing)
|
||||
create_inbound_email file_fixture(fixture_name).open, filename: fixture_name, status: status
|
||||
end
|
||||
|
||||
ActionMailroom::InboundEmail.create!(status: status, raw_email: raw_email)
|
||||
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
|
||||
|
|
|
@ -5,7 +5,7 @@ class ActionMailroom::InboundEmail::IncinerationTest < ActiveSupport::TestCase
|
|||
freeze_time
|
||||
|
||||
assert_enqueued_with job: ActionMailroom::InboundEmail::IncinerationJob, at: 30.days.from_now do
|
||||
create_inbound_email("welcome.eml").delivered!
|
||||
create_inbound_email_from_fixture("welcome.eml").delivered!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ end
|
|||
class ActionMailroom::Mailbox::CallbacksTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
$before_processing = $after_processing = $around_processing = $processed = false
|
||||
@inbound_email = create_inbound_email("welcome.eml")
|
||||
@inbound_email = create_inbound_email_from_fixture("welcome.eml")
|
||||
end
|
||||
|
||||
test "all callback types" do
|
||||
|
|
|
@ -13,7 +13,7 @@ end
|
|||
class ActionMailroom::Mailbox::RoutingTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
$processed = false
|
||||
@inbound_email = create_inbound_email("welcome.eml")
|
||||
@inbound_email = create_inbound_email_from_fixture("welcome.eml")
|
||||
end
|
||||
|
||||
test "string routing" do
|
||||
|
@ -23,7 +23,7 @@ class ActionMailroom::Mailbox::RoutingTest < ActiveSupport::TestCase
|
|||
|
||||
test "delayed routing" do
|
||||
perform_enqueued_jobs only: ActionMailroom::RoutingJob do
|
||||
another_inbound_email = create_inbound_email("welcome.eml", status: :pending)
|
||||
another_inbound_email = create_inbound_email_from_fixture("welcome.eml", status: :pending)
|
||||
assert_equal "Discussion: Let's debate these attachments", $processed
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ end
|
|||
class ActionMailroom::Mailbox::StateTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
$processed = false
|
||||
@inbound_email = create_inbound_email("welcome.eml")
|
||||
@inbound_email = create_inbound_email_from_fixture("welcome.eml")
|
||||
end
|
||||
|
||||
test "successful mailbox processing leaves inbound email in delivered state" do
|
||||
|
|
|
@ -15,8 +15,12 @@ module ActionMailroom
|
|||
end
|
||||
|
||||
test "routed to mailbox" do
|
||||
@router.route create_inbound_email("welcome.eml")
|
||||
assert_equal "Discussion: Let's debate these attachments", $processed
|
||||
@router.route create_inbound_email_from_mail {
|
||||
to "replies@example.com"
|
||||
subject "This is a reply"
|
||||
}
|
||||
|
||||
assert_equal "This is a reply", $processed
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue