2010-01-13 10:56:11 +00:00
|
|
|
require "abstract_unit"
|
2011-05-25 02:31:56 +00:00
|
|
|
require 'mailers/base_mailer'
|
2010-06-24 11:23:43 +00:00
|
|
|
require "active_support/log_subscriber/test_helper"
|
|
|
|
require "action_mailer/log_subscriber"
|
2010-01-13 10:56:11 +00:00
|
|
|
|
2010-02-15 14:44:30 +00:00
|
|
|
class AMLogSubscriberTest < ActionMailer::TestCase
|
2010-06-24 11:23:43 +00:00
|
|
|
include ActiveSupport::LogSubscriber::TestHelper
|
2010-03-03 06:55:09 +00:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
2010-06-24 11:23:43 +00:00
|
|
|
ActionMailer::LogSubscriber.attach_to :action_mailer
|
2010-03-03 06:55:09 +00:00
|
|
|
end
|
2010-01-13 10:56:11 +00:00
|
|
|
|
|
|
|
class TestMailer < ActionMailer::Base
|
|
|
|
def receive(mail)
|
|
|
|
# Do nothing
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_logger(logger)
|
|
|
|
ActionMailer::Base.logger = logger
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_deliver_is_notified
|
2011-05-24 16:52:11 +00:00
|
|
|
BaseMailer.welcome.deliver
|
2010-01-13 10:56:11 +00:00
|
|
|
wait
|
2010-01-24 16:31:18 +00:00
|
|
|
assert_equal(1, @logger.logged(:info).size)
|
2011-05-24 16:52:11 +00:00
|
|
|
assert_match(/Sent mail to system@test.lindsaar.net/, @logger.logged(:info).first)
|
2010-01-24 16:31:18 +00:00
|
|
|
assert_equal(1, @logger.logged(:debug).size)
|
2011-05-24 16:52:11 +00:00
|
|
|
assert_match(/Welcome/, @logger.logged(:debug).first)
|
2010-01-13 10:56:11 +00:00
|
|
|
end
|
|
|
|
|
2010-01-15 10:24:06 +00:00
|
|
|
def test_receive_is_notified
|
2010-01-13 10:56:11 +00:00
|
|
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email")
|
|
|
|
TestMailer.receive(fixture)
|
|
|
|
wait
|
2010-01-24 16:31:18 +00: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 10:56:11 +00:00
|
|
|
end
|
|
|
|
end
|