2010-01-13 05:56:11 -05:00
|
|
|
require "abstract_unit"
|
2010-02-15 09:44:30 -05:00
|
|
|
require "rails/log_subscriber/test_helper"
|
|
|
|
require "action_mailer/railties/log_subscriber"
|
2010-01-13 05:56:11 -05:00
|
|
|
|
2010-02-15 09:44:30 -05:00
|
|
|
class AMLogSubscriberTest < ActionMailer::TestCase
|
|
|
|
include Rails::LogSubscriber::TestHelper
|
2010-03-03 01:55:09 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
Rails::LogSubscriber.add(:action_mailer, ActionMailer::Railties::LogSubscriber.new)
|
|
|
|
end
|
2010-01-13 05:56:11 -05:00
|
|
|
|
|
|
|
class TestMailer < ActionMailer::Base
|
|
|
|
def basic
|
|
|
|
recipients "somewhere@example.com"
|
|
|
|
subject "basic"
|
|
|
|
from "basic@example.com"
|
2010-01-26 13:15:20 -05:00
|
|
|
body "Hello world"
|
2010-01-13 05:56:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def receive(mail)
|
|
|
|
# Do nothing
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_logger(logger)
|
|
|
|
ActionMailer::Base.logger = logger
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_deliver_is_notified
|
2010-01-24 11:31:18 -05:00
|
|
|
TestMailer.basic.deliver
|
2010-01-13 05:56:11 -05:00
|
|
|
wait
|
2010-01-24 11:31:18 -05:00
|
|
|
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)
|
2010-01-13 05:56:11 -05:00
|
|
|
end
|
|
|
|
|
2010-01-15 05:24:06 -05:00
|
|
|
def test_receive_is_notified
|
2010-01-13 05:56:11 -05:00
|
|
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email")
|
|
|
|
TestMailer.receive(fixture)
|
|
|
|
wait
|
2010-01-24 11:31:18 -05:00
|
|
|
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)
|
2010-01-13 05:56:11 -05:00
|
|
|
end
|
|
|
|
end
|