diff options
Diffstat (limited to 'actionmailer/test')
-rw-r--r-- | actionmailer/test/abstract_unit.rb | 5 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 83 | ||||
-rw-r--r-- | actionmailer/test/log_subscriber_test.rb (renamed from actionmailer/test/subscriber_test.rb) | 14 | ||||
-rw-r--r-- | actionmailer/test/old_base/asset_host_test.rb | 9 | ||||
-rw-r--r-- | actionmailer/test/old_base/url_test.rb | 10 |
5 files changed, 89 insertions, 32 deletions
diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index f6baa4a9e8..16fef3a9a4 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -1,5 +1,8 @@ require File.expand_path('../../../load_paths', __FILE__) +lib = File.expand_path("#{File.dirname(__FILE__)}/../lib") +$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) + require 'test/unit' require 'action_mailer' require 'action_mailer/test_case' @@ -14,7 +17,7 @@ ActionView::Template.register_template_handler :bak, lambda { |template| "Lame b FIXTURE_LOAD_PATH = File.expand_path('fixtures', File.dirname(__FILE__)) ActionMailer::Base.view_paths = FIXTURE_LOAD_PATH -class MockSMTP +class MockSMTP def self.deliveries @@deliveries end diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index 222db66aaa..c1cf1f0157 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -14,8 +14,13 @@ class BaseTest < ActiveSupport::TestCase mail({:subject => "The first email on new API!"}.merge!(hash)) end - def simple(hash = {}) - mail(hash) + def welcome_with_headers(hash = {}) + headers hash + mail + end + + def welcome_from_another_path(path) + mail(:template_name => "welcome", :template_path => path) end def html_only(hash = {}) @@ -25,11 +30,6 @@ class BaseTest < ActiveSupport::TestCase def plain_text_only(hash = {}) mail(hash) end - - def simple_with_headers(hash = {}) - headers hash - mail - end def attachment_with_content(hash = {}) attachments['invoice.pdf'] = 'This is test File content' @@ -78,8 +78,12 @@ class BaseTest < ActiveSupport::TestCase format.html{ render "welcome" } if include_html end end - - def different_template(template_name='') + + def implicit_different_template(template_name='') + mail(:template_name => template_name) + end + + def explicit_different_template(template_name='') mail do |format| format.text { render :template => "#{mailer_name}/#{template_name}" } format.html { render :template => "#{mailer_name}/#{template_name}" } @@ -88,13 +92,10 @@ class BaseTest < ActiveSupport::TestCase def different_layout(layout_name='') mail do |format| - format.text { - render :layout => layout_name - } + format.text { render :layout => layout_name } format.html { render :layout => layout_name } end end - end test "method call to mail does not raise error" do @@ -154,7 +155,7 @@ class BaseTest < ActiveSupport::TestCase test "can pass random headers in as a hash to mail" do hash = {'X-Special-Domain-Specific-Header' => "SecretValue", 'In-Reply-To' => '1234@mikel.me.com' } - mail = BaseMailer.simple(hash) + mail = BaseMailer.welcome(hash) assert_equal('SecretValue', mail['X-Special-Domain-Specific-Header'].decoded) assert_equal('1234@mikel.me.com', mail['In-Reply-To'].decoded) end @@ -162,7 +163,7 @@ class BaseTest < ActiveSupport::TestCase test "can pass random headers in as a hash" do hash = {'X-Special-Domain-Specific-Header' => "SecretValue", 'In-Reply-To' => '1234@mikel.me.com' } - mail = BaseMailer.simple_with_headers(hash) + mail = BaseMailer.welcome_with_headers(hash) assert_equal('SecretValue', mail['X-Special-Domain-Specific-Header'].decoded) assert_equal('1234@mikel.me.com', mail['In-Reply-To'].decoded) end @@ -247,9 +248,9 @@ class BaseTest < ActiveSupport::TestCase end test "uses random default headers from class" do - with_default BaseMailer, "X-SPAM" => "Not spam" do - email = BaseMailer.simple - assert_equal("Not spam", email["X-SPAM"].decoded) + with_default BaseMailer, "X-Custom" => "Custom" do + email = BaseMailer.welcome + assert_equal("Custom", email["X-Custom"].decoded) end end @@ -476,18 +477,58 @@ class BaseTest < ActiveSupport::TestCase end # Rendering - test "that you can specify a different template" do - mail = BaseMailer.different_template('explicit_multipart_templates') + test "you can specify a different template for implicit render" do + mail = BaseMailer.implicit_different_template('implicit_multipart') + assert_equal("HTML Implicit Multipart", mail.html_part.body.decoded) + assert_equal("TEXT Implicit Multipart", mail.text_part.body.decoded) + end + + test "you can specify a different template for explicit render" do + mail = BaseMailer.explicit_different_template('explicit_multipart_templates') assert_equal("HTML Explicit Multipart Templates", mail.html_part.body.decoded) assert_equal("TEXT Explicit Multipart Templates", mail.text_part.body.decoded) end - test "that you can specify a different layout" do + test "you can specify a different layout" do mail = BaseMailer.different_layout('different_layout') assert_equal("HTML -- HTML", mail.html_part.body.decoded) assert_equal("PLAIN -- PLAIN", mail.text_part.body.decoded) end + test "you can specify the template path for implicit lookup" do + mail = BaseMailer.welcome_from_another_path('another.path/base_mailer') + assert_equal("Welcome from another path", mail.body.encoded) + + mail = BaseMailer.welcome_from_another_path(['unknown/invalid', 'another.path/base_mailer']) + assert_equal("Welcome from another path", mail.body.encoded) + end + + # Before and After hooks + + class MyObserver + def self.delivered_email(mail) + end + end + + test "you can register an observer to the mail object that gets informed on email delivery" do + ActionMailer::Base.register_observer(MyObserver) + mail = BaseMailer.welcome + MyObserver.expects(:delivered_email).with(mail) + mail.deliver + end + + class MyInterceptor + def self.delivering_email(mail) + end + end + + test "you can register an interceptor to the mail object that gets passed the mail object before delivery" do + ActionMailer::Base.register_interceptor(MyInterceptor) + mail = BaseMailer.welcome + MyInterceptor.expects(:delivering_email).with(mail) + mail.deliver + end + protected # Execute the block setting the given values and restoring old values after diff --git a/actionmailer/test/subscriber_test.rb b/actionmailer/test/log_subscriber_test.rb index 3d1736d64f..c08c34b4a2 100644 --- a/actionmailer/test/subscriber_test.rb +++ b/actionmailer/test/log_subscriber_test.rb @@ -1,10 +1,14 @@ require "abstract_unit" -require "rails/subscriber/test_helper" -require "action_mailer/railties/subscriber" +require "rails/log_subscriber/test_helper" +require "action_mailer/railties/log_subscriber" -class AMSubscriberTest < ActionMailer::TestCase - include Rails::Subscriber::TestHelper - Rails::Subscriber.add(:action_mailer, ActionMailer::Railties::Subscriber.new) +class AMLogSubscriberTest < ActionMailer::TestCase + include Rails::LogSubscriber::TestHelper + + def setup + super + Rails::LogSubscriber.add(:action_mailer, ActionMailer::Railties::LogSubscriber.new) + end class TestMailer < ActionMailer::Base def basic diff --git a/actionmailer/test/old_base/asset_host_test.rb b/actionmailer/test/old_base/asset_host_test.rb index aa9cfd88dd..0ec0242f55 100644 --- a/actionmailer/test/old_base/asset_host_test.rb +++ b/actionmailer/test/old_base/asset_host_test.rb @@ -14,6 +14,10 @@ class AssetHostTest < Test::Unit::TestCase set_delivery_method :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.deliveries.clear + AssetHostMailer.configure do |c| + c.asset_host = "http://www.example.com" + c.assets_dir = '' + end end def teardown @@ -21,13 +25,12 @@ class AssetHostTest < Test::Unit::TestCase end def test_asset_host_as_string - ActionController::Base.asset_host = "http://www.example.com" mail = AssetHostMailer.email_with_asset assert_equal "<img alt=\"Somelogo\" src=\"http://www.example.com/images/somelogo.png\" />", mail.body.to_s.strip end def test_asset_host_as_one_arguement_proc - ActionController::Base.asset_host = Proc.new { |source| + AssetHostMailer.config.asset_host = Proc.new { |source| if source.starts_with?('/images') "http://images.example.com" else @@ -39,7 +42,7 @@ class AssetHostTest < Test::Unit::TestCase end def test_asset_host_as_two_arguement_proc - ActionController::Base.asset_host = Proc.new {|source,request| + ActionController::Base.config.asset_host = Proc.new {|source,request| if request && request.ssl? "https://www.example.com" else diff --git a/actionmailer/test/old_base/url_test.rb b/actionmailer/test/old_base/url_test.rb index d851431c7a..60740d6b0b 100644 --- a/actionmailer/test/old_base/url_test.rb +++ b/actionmailer/test/old_base/url_test.rb @@ -4,13 +4,19 @@ require 'action_controller' class WelcomeController < ActionController::Base end +AppRoutes = ActionDispatch::Routing::RouteSet.new + class ActionMailer::Base - include ActionController::UrlFor + include AppRoutes.url_helpers end class TestMailer < ActionMailer::Base default_url_options[:host] = 'www.basecamphq.com' + configure do |c| + c.assets_dir = '' # To get the tests to pass + end + def signed_up_with_url(recipient) @recipients = recipient @subject = "[Signed up] Welcome #{recipient}" @@ -61,7 +67,7 @@ class ActionMailerUrlTest < Test::Unit::TestCase def test_signed_up_with_url TestMailer.delivery_method = :test - ActionController::Routing::Routes.draw do |map| + AppRoutes.draw do |map| map.connect ':controller/:action/:id' map.welcome 'welcome', :controller=>"foo", :action=>"bar" end |