diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-13 11:56:11 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-14 01:07:03 +0100 |
commit | 2a6bc1263e99060897b53a8c806916d198eab572 (patch) | |
tree | 89198bdaf7ffdcafae1039be17ab8a9d04faf7db /actionmailer/test | |
parent | d01716731bd9c68de686d6ac85e3da5251305495 (diff) | |
download | rails-2a6bc1263e99060897b53a8c806916d198eab572.tar.gz rails-2a6bc1263e99060897b53a8c806916d198eab572.tar.bz2 rails-2a6bc1263e99060897b53a8c806916d198eab572.zip |
Add subscriber to ActionMailer.
Diffstat (limited to 'actionmailer/test')
-rw-r--r-- | actionmailer/test/mail_service_test.rb | 34 | ||||
-rw-r--r-- | actionmailer/test/subscriber_test.rb | 53 |
2 files changed, 53 insertions, 34 deletions
diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 9b3da299ba..cd41739f1a 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -688,40 +688,6 @@ class ActionMailerTest < Test::Unit::TestCase TestMailer.deliver_signed_up(@recipient) end - class FakeLogger - attr_reader :info_contents, :debug_contents - - def initialize - @info_contents, @debug_contents = "", "" - end - - def info(str = nil, &blk) - @info_contents << str if str - @info_contents << blk.call if block_given? - end - - def debug(str = nil, &blk) - @debug_contents << str if str - @debug_contents << blk.call if block_given? - end - end - - def test_delivery_logs_sent_mail - mail = TestMailer.create_signed_up(@recipient) - # logger = mock() - # logger.expects(:info).with("Sent mail to #{@recipient}") - # logger.expects(:debug).with("\n#{mail.encoded}") - TestMailer.logger = FakeLogger.new - TestMailer.deliver_signed_up(@recipient) - assert(TestMailer.logger.info_contents =~ /Sent mail to #{@recipient}/) - expected = TestMailer.logger.debug_contents - actual = "\n#{mail.encoded}" - expected.gsub!(/Message-ID:.*\r\n/, "Message-ID: <123@456>\r\n") - actual.gsub!(/Message-ID:.*\r\n/, "Message-ID: <123@456>\r\n") - - assert_equal(expected, actual) - end - def test_unquote_quoted_printable_subject msg = <<EOF From: me@example.com diff --git a/actionmailer/test/subscriber_test.rb b/actionmailer/test/subscriber_test.rb new file mode 100644 index 0000000000..aab53b385f --- /dev/null +++ b/actionmailer/test/subscriber_test.rb @@ -0,0 +1,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_notifier + 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
\ No newline at end of file |