diff options
Diffstat (limited to 'actionmailer/test')
-rw-r--r-- | actionmailer/test/abstract_unit.rb | 14 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 50 | ||||
-rw-r--r-- | actionmailer/test/i18n_with_controller_test.rb | 2 | ||||
-rw-r--r-- | actionmailer/test/mail_helper_test.rb | 44 | ||||
-rw-r--r-- | actionmailer/test/url_test.rb | 4 |
5 files changed, 97 insertions, 17 deletions
diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 3a519253f9..487102b564 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -1,16 +1,4 @@ -# Pathname has a warning, so require it first while silencing -# warnings to shut it up. -# -# Also, in 1.9, Bundler creates warnings due to overriding -# Rubygems methods -begin - old, $VERBOSE = $VERBOSE, nil - require 'pathname' - require File.expand_path('../../../load_paths', __FILE__) -ensure - $VERBOSE = old -end - +require File.expand_path('../../../load_paths', __FILE__) require 'active_support/core_ext/kernel/reporting' # These are the normal settings that will be set up by Railties diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index 65550ab505..aed3ee1874 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -1,5 +1,7 @@ # encoding: utf-8 require 'abstract_unit' +require 'set' + require 'active_support/time' require 'mailers/base_mailer' @@ -550,6 +552,52 @@ class BaseTest < ActiveSupport::TestCase assert_equal("Thanks for signing up this afternoon", mail.subject) end + test "modifying the mail message with a before_filter" do + class BeforeFilterMailer < ActionMailer::Base + before_filter :add_special_header! + + def welcome ; mail ; end + + private + def add_special_header! + headers('X-Special-Header' => 'Wow, so special') + end + end + + assert_equal('Wow, so special', BeforeFilterMailer.welcome['X-Special-Header'].to_s) + end + + test "modifying the mail message with an after_filter" do + class AfterFilterMailer < ActionMailer::Base + after_filter :add_special_header! + + def welcome ; mail ; end + + private + def add_special_header! + headers('X-Special-Header' => 'Testing') + end + end + + assert_equal('Testing', AfterFilterMailer.welcome['X-Special-Header'].to_s) + end + + test "adding an inline attachment using a before_filter" do + class DefaultInlineAttachmentMailer < ActionMailer::Base + before_filter :add_inline_attachment! + + def welcome ; mail ; end + + private + def add_inline_attachment! + attachments.inline["footer.jpg"] = 'hey there' + end + end + + mail = DefaultInlineAttachmentMailer.welcome + assert_equal('image/jpeg; filename=footer.jpg', mail.attachments.inline.first['Content-Type'].to_s) + end + test "action methods should be refreshed after defining new method" do class FooMailer < ActionMailer::Base # this triggers action_methods @@ -559,7 +607,7 @@ class BaseTest < ActiveSupport::TestCase end end - assert_equal ["notify"], FooMailer.action_methods + assert_equal Set.new(["notify"]), FooMailer.action_methods end protected diff --git a/actionmailer/test/i18n_with_controller_test.rb b/actionmailer/test/i18n_with_controller_test.rb index 7040ae6f8d..68ed86e0d4 100644 --- a/actionmailer/test/i18n_with_controller_test.rb +++ b/actionmailer/test/i18n_with_controller_test.rb @@ -24,7 +24,7 @@ end class ActionMailerI18nWithControllerTest < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new Routes.draw do - match ':controller(/:action(/:id))' + get ':controller(/:action(/:id))' end def app diff --git a/actionmailer/test/mail_helper_test.rb b/actionmailer/test/mail_helper_test.rb index 17e9c82045..d8a73e6c46 100644 --- a/actionmailer/test/mail_helper_test.rb +++ b/actionmailer/test/mail_helper_test.rb @@ -22,6 +22,14 @@ class HelperMailer < ActionMailer::Base end end + def use_format_paragraph_with_long_first_word + @text = "Antidisestablishmentarianism is very long." + + mail_with_defaults do |format| + format.html { render(:inline => "<%= format_paragraph @text, 10, 1 %>") } + end + end + def use_mailer mail_with_defaults do |format| format.html { render(:inline => "<%= mailer.message.subject %>") } @@ -34,6 +42,23 @@ class HelperMailer < ActionMailer::Base end end + def use_block_format + @text = <<-TEXT +This is the +first paragraph. + +The second + paragraph. + +* item1 * item2 + * item3 + TEXT + + mail_with_defaults do |format| + format.html { render(:inline => "<%= block_format @text %>") } + end + end + protected def mail_with_defaults(&block) @@ -63,5 +88,24 @@ class MailerHelperTest < ActionMailer::TestCase mail = HelperMailer.use_format_paragraph assert_match " But soft! What\r\n light through\r\n yonder window\r\n breaks?", mail.body.encoded end + + def test_use_format_paragraph_with_long_first_word + mail = HelperMailer.use_format_paragraph_with_long_first_word + assert_equal " Antidisestablishmentarianism\r\n is very\r\n long.", mail.body.encoded + end + + def test_use_block_format + mail = HelperMailer.use_block_format + expected = <<-TEXT + This is the first paragraph. + + The second paragraph. + + * item1 + * item2 + * item3 + TEXT + assert_equal expected.gsub("\n", "\r\n"), mail.body.encoded + end end diff --git a/actionmailer/test/url_test.rb b/actionmailer/test/url_test.rb index 0536e83098..2ea1723434 100644 --- a/actionmailer/test/url_test.rb +++ b/actionmailer/test/url_test.rb @@ -57,8 +57,8 @@ class ActionMailerUrlTest < ActionMailer::TestCase UrlTestMailer.delivery_method = :test AppRoutes.draw do - match ':controller(/:action(/:id))' - match '/welcome' => "foo#bar", :as => "welcome" + get ':controller(/:action(/:id))' + get '/welcome' => "foo#bar", :as => "welcome" end expected = new_mail |