2010-01-13 05:56:11 -05:00
|
|
|
require "abstract_unit"
|
|
|
|
require "rails/subscriber/test_helper"
|
|
|
|
require "action_mailer/railties/subscriber"
|
|
|
|
|
2010-01-21 07:05:30 -05:00
|
|
|
class AMSubscriberTest < ActionMailer::TestCase
|
|
|
|
include Rails::Subscriber::TestHelper
|
2010-01-13 05:56:11 -05:00
|
|
|
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
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
end
|