aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test/subscriber_test.rb
blob: 01a71f481d3f37ebf7b284cfca4e5f0f47085f27 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require "abstract_unit"
require "rails/subscriber/test_helper"
require "action_mailer/railties/subscriber"

module SubscriberTest
  Rails::Subscriber.add(:action_mailer, ActionMailer::Railties::Subscriber.new)

  class TestMailer < ActionMailer::Base
    def basic
      recipients "somewhere@example.com"
      subject    "basic"
      from       "basic@example.com"
      render :text => "Hello world"
    end

    def receive(mail)
      # Do nothing
    end
  end

  def set_logger(logger)
    ActionMailer::Base.logger = logger
  end

  def test_deliver_is_notified
    TestMailer.deliver_basic
    wait
    assert_equal 1, @logger.logged(:info).size
    assert_match /Sent mail to somewhere@example.com/, @logger.logged(:info).first
    assert_equal 1, @logger.logged(:debug).size
    assert_match /Hello world/, @logger.logged(:debug).first
  end

  def test_receive_is_notified
    fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email")
    TestMailer.receive(fixture)
    wait
    assert_equal 1, @logger.logged(:info).size
    assert_match /Received mail/, @logger.logged(:info).first
    assert_equal 1, @logger.logged(:debug).size
    assert_match /Jamis/, @logger.logged(:debug).first
  end

  class SyncSubscriberTest < ActionMailer::TestCase
    include Rails::Subscriber::SyncTestHelper
    include SubscriberTest
  end

  class AsyncSubscriberTest < ActionMailer::TestCase
    include Rails::Subscriber::AsyncTestHelper
    include SubscriberTest
  end
end