1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionmailbox/test/unit/mailbox/state_test.rb

52 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
2018-12-24 15:16:22 -05:00
require_relative "../../test_helper"
class SuccessfulMailbox < ActionMailbox::Base
def process
$processed = mail.subject
end
end
class UnsuccessfulMailbox < ActionMailbox::Base
rescue_from(RuntimeError) { $processed = :failure }
def process
raise "No way!"
end
end
class BouncingMailbox < ActionMailbox::Base
def process
$processed = :bounced
2018-12-24 15:16:22 -05:00
bounced!
end
end
class ActionMailbox::Base::StateTest < ActiveSupport::TestCase
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"
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
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
test "bounced inbound emails are not delivered" do
BouncingMailbox.receive @inbound_email
assert @inbound_email.bounced?
assert_equal :bounced, $processed
end
end