Sha256: 061f6cd7047308a598020dab7ef5dd954d857a94ab27fa6c53053b485c2d3f3f

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

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
    bounced!    
  end
end


class ActionMailbox::Base::StateTest < ActiveSupport::TestCase
  setup do
    $processed = false
    @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?
    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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
actionmailbox-0.1.0 test/unit/mailbox/state_test.rb