2018-12-14 05:06:12 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-24 15:16:22 -05:00
|
|
|
require_relative "../../test_helper"
|
2018-09-18 19:42:27 -04:00
|
|
|
|
2018-09-28 15:19:43 -04:00
|
|
|
class SuccessfulMailbox < ActionMailbox::Base
|
2018-09-18 19:42:27 -04:00
|
|
|
def process
|
|
|
|
$processed = mail.subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-28 15:19:43 -04:00
|
|
|
class UnsuccessfulMailbox < ActionMailbox::Base
|
2018-09-18 19:42:27 -04:00
|
|
|
rescue_from(RuntimeError) { $processed = :failure }
|
|
|
|
|
|
|
|
def process
|
|
|
|
raise "No way!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-28 15:19:43 -04:00
|
|
|
class BouncingMailbox < ActionMailbox::Base
|
2018-09-21 19:44:48 -04:00
|
|
|
def process
|
|
|
|
$processed = :bounced
|
2018-12-24 15:16:22 -05:00
|
|
|
bounced!
|
2018-09-21 19:44:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2018-09-28 15:19:43 -04:00
|
|
|
class ActionMailbox::Base::StateTest < ActiveSupport::TestCase
|
2018-09-18 19:42:27 -04:00
|
|
|
setup do
|
|
|
|
$processed = false
|
2018-09-19 20:13:57 -04:00
|
|
|
@inbound_email = create_inbound_email_from_mail \
|
|
|
|
to: "replies@example.com", subject: "I was processed"
|
2018-09-18 19:42:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "successful mailbox processing leaves inbound email in delivered state" do
|
|
|
|
SuccessfulMailbox.receive @inbound_email
|
|
|
|
assert @inbound_email.delivered?
|
2018-09-19 20:13:57 -04:00
|
|
|
assert_equal "I was processed", $processed
|
2018-09-18 19:42:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "unsuccessful mailbox processing leaves inbound email in failed state" do
|
|
|
|
UnsuccessfulMailbox.receive @inbound_email
|
|
|
|
assert @inbound_email.failed?
|
|
|
|
assert_equal :failure, $processed
|
|
|
|
end
|
2018-09-21 19:44:48 -04:00
|
|
|
|
|
|
|
test "bounced inbound emails are not delivered" do
|
|
|
|
BouncingMailbox.receive @inbound_email
|
|
|
|
assert @inbound_email.bounced?
|
|
|
|
assert_equal :bounced, $processed
|
|
|
|
end
|
2018-09-18 19:42:27 -04:00
|
|
|
end
|