aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/mailbox/callbacks_test.rb
blob: 4cafeb35347da2a8402e2e21cff9afa978160064 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require_relative '../../test_helper'

class CallbackMailbox < ActionMailroom::Mailbox
  before_processing { $before_processing = "Ran that!" }
  after_processing  { $after_processing = "Ran that too!" }
  around_processing ->(r, block) { block.call; $around_processing = "Ran that as well!" }

  def process
    $processed = mail.subject
  end
end

class ActionMailroom::Mailbox::CallbacksTest < ActiveSupport::TestCase
  setup do
    $before_processing = $after_processing = $around_processing = $processed = false
    @inbound_email = create_inbound_email_from_fixture("welcome.eml")
  end

  test "all callback types" do
    CallbackMailbox.receive @inbound_email
    assert_equal "Ran that!", $before_processing
    assert_equal "Ran that too!", $after_processing
    assert_equal "Ran that as well!", $around_processing
  end
end