diff options
author | Rizwan Reza <rizwanreza@gmail.com> | 2010-03-28 12:04:00 +0430 |
---|---|---|
committer | Rizwan Reza <rizwanreza@gmail.com> | 2010-03-28 12:04:00 +0430 |
commit | b4c91de9462f59d6395c7c871aafa3301afdc383 (patch) | |
tree | fadcaf603a6f473e8ccd52070a1f3b4f957c34cb /actionmailer/test | |
parent | 4b4f69b9bfbd33556e23262f57cf6d944dfd9f63 (diff) | |
parent | 66d57d7ba83df52ff1e0485c89f6192c2f84c6b8 (diff) | |
download | rails-b4c91de9462f59d6395c7c871aafa3301afdc383.tar.gz rails-b4c91de9462f59d6395c7c871aafa3301afdc383.tar.bz2 rails-b4c91de9462f59d6395c7c871aafa3301afdc383.zip |
Merge remote branch 'rails/master'
Diffstat (limited to 'actionmailer/test')
-rw-r--r-- | actionmailer/test/abstract_unit.rb | 21 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 58 | ||||
-rw-r--r-- | actionmailer/test/fixtures/base_mailer/explicit_multipart_with_one_template.erb | 1 | ||||
-rw-r--r-- | actionmailer/test/fixtures/url_test_mailer/signed_up_with_url.erb (renamed from actionmailer/test/fixtures/test_mailer/signed_up_with_url.erb) | 0 | ||||
-rw-r--r-- | actionmailer/test/old_base/mail_layout_test.rb | 22 | ||||
-rw-r--r-- | actionmailer/test/old_base/mail_service_test.rb | 6 | ||||
-rw-r--r-- | actionmailer/test/old_base/url_test.rb | 16 |
7 files changed, 65 insertions, 59 deletions
diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 16fef3a9a4..ea15709b45 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -1,4 +1,23 @@ -require File.expand_path('../../../load_paths', __FILE__) +# 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 'active_support/core_ext/kernel/reporting' +silence_warnings do + # These external dependencies have warnings :/ + require 'text/format' + require 'mail' +end lib = File.expand_path("#{File.dirname(__FILE__)}/../lib") $:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index f5fd12a6b0..6f274c11df 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -74,13 +74,20 @@ class BaseTest < ActiveSupport::TestCase end end - def custom_block(include_html=false) + def explicit_multipart_with_options(include_html = false) mail do |format| format.text(:content_transfer_encoding => "base64"){ render "welcome" } format.html{ render "welcome" } if include_html end end + def explicit_multipart_with_one_template(hash = {}) + mail(hash) do |format| + format.html + format.text + end + end + def implicit_different_template(template_name='') mail(:template_name => template_name) end @@ -148,6 +155,13 @@ class BaseTest < ActiveSupport::TestCase assert_equal("Hello there", email.body.encoded) end + test "should set template content type if mail has only one part" do + mail = BaseMailer.html_only + assert_equal('text/html', mail.mime_type) + mail = BaseMailer.plain_text_only + assert_equal('text/plain', mail.mime_type) + end + # Custom headers test "custom headers" do email = BaseMailer.welcome @@ -162,7 +176,7 @@ class BaseTest < ActiveSupport::TestCase assert_equal('1234@mikel.me.com', mail['In-Reply-To'].decoded) end - test "can pass random headers in as a hash" do + test "can pass random headers in as a hash to headers" do hash = {'X-Special-Domain-Specific-Header' => "SecretValue", 'In-Reply-To' => '1234@mikel.me.com' } mail = BaseMailer.welcome_with_headers(hash) @@ -366,6 +380,11 @@ class BaseTest < ActiveSupport::TestCase assert_equal("HTML Explicit Multipart", email.parts[1].body.encoded) end + test "explicit multipart have a boundary" do + mail = BaseMailer.explicit_multipart + assert_not_nil(mail.content_type_parameters[:boundary]) + end + test "explicit multipart does not sort order" do order = ["text/html", "text/plain"] with_default BaseMailer, :parts_order => order do @@ -399,7 +418,7 @@ class BaseTest < ActiveSupport::TestCase assert_equal("TEXT Explicit Multipart Templates", email.parts[1].body.encoded) end - test "explicit multipart with any" do + test "explicit multipart with format.any" do email = BaseMailer.explicit_multipart_with_any assert_equal(2, email.parts.size) assert_equal("multipart/alternative", email.mime_type) @@ -409,8 +428,8 @@ class BaseTest < ActiveSupport::TestCase assert_equal("Format with any!", email.parts[1].body.encoded) end - test "explicit multipart with options" do - email = BaseMailer.custom_block(true) + test "explicit multipart with format(Hash)" do + email = BaseMailer.explicit_multipart_with_options(true) email.ready_to_send! assert_equal(2, email.parts.size) assert_equal("multipart/alternative", email.mime_type) @@ -420,28 +439,23 @@ class BaseTest < ActiveSupport::TestCase assert_equal("7bit", email.parts[1].content_transfer_encoding) end - test "explicit multipart should be multipart" do - mail = BaseMailer.explicit_multipart - assert_not_nil(mail.content_type_parameters[:boundary]) - end - - test "should set a content type if only has an html part" do - mail = BaseMailer.html_only - assert_equal('text/html', mail.mime_type) - end - - test "should set a content type if only has an plain text part" do - mail = BaseMailer.plain_text_only - assert_equal('text/plain', mail.mime_type) - end - - test "explicit multipart with one part is rendered as body" do - email = BaseMailer.custom_block + test "explicit multipart with one part is rendered as body and options are merged" do + email = BaseMailer.explicit_multipart_with_options assert_equal(0, email.parts.size) assert_equal("text/plain", email.mime_type) assert_equal("base64", email.content_transfer_encoding) end + test "explicit multipart with one template has the expected format" do + email = BaseMailer.explicit_multipart_with_one_template + assert_equal(2, email.parts.size) + assert_equal("multipart/alternative", email.mime_type) + assert_equal("text/html", email.parts[0].mime_type) + assert_equal("[:html]", email.parts[0].body.encoded) + assert_equal("text/plain", email.parts[1].mime_type) + assert_equal("[:text]", email.parts[1].body.encoded) + end + # Class level API with method missing test "should respond to action methods" do assert BaseMailer.respond_to?(:welcome) diff --git a/actionmailer/test/fixtures/base_mailer/explicit_multipart_with_one_template.erb b/actionmailer/test/fixtures/base_mailer/explicit_multipart_with_one_template.erb new file mode 100644 index 0000000000..8a69657b08 --- /dev/null +++ b/actionmailer/test/fixtures/base_mailer/explicit_multipart_with_one_template.erb @@ -0,0 +1 @@ +<%= self.formats.inspect %>
\ No newline at end of file diff --git a/actionmailer/test/fixtures/test_mailer/signed_up_with_url.erb b/actionmailer/test/fixtures/url_test_mailer/signed_up_with_url.erb index 4c5806d30d..4c5806d30d 100644 --- a/actionmailer/test/fixtures/test_mailer/signed_up_with_url.erb +++ b/actionmailer/test/fixtures/url_test_mailer/signed_up_with_url.erb diff --git a/actionmailer/test/old_base/mail_layout_test.rb b/actionmailer/test/old_base/mail_layout_test.rb index 5679aa5a64..2c2daa0f28 100644 --- a/actionmailer/test/old_base/mail_layout_test.rb +++ b/actionmailer/test/old_base/mail_layout_test.rb @@ -69,47 +69,25 @@ class LayoutMailerTest < Test::Unit::TestCase def test_should_pickup_multipart_layout mail = AutoLayoutMailer.multipart - # CHANGED: content_type returns an object - # assert_equal "multipart/alternative", mail.content_type assert_equal "multipart/alternative", mail.mime_type assert_equal 2, mail.parts.size - # CHANGED: content_type returns an object - # assert_equal 'text/plain', mail.parts.first.content_type assert_equal 'text/plain', mail.parts.first.mime_type - - # CHANGED: body returns an object - # assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s - # CHANGED: content_type returns an object - # assert_equal 'text/html', mail.parts.last.content_type assert_equal 'text/html', mail.parts.last.mime_type - - # CHANGED: body returns an object - # assert_equal "Hello from layout text/html multipart", mail.parts.last.body assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s end def test_should_pickup_multipartmixed_layout mail = AutoLayoutMailer.multipart("multipart/mixed") - # CHANGED: content_type returns an object - # assert_equal "multipart/mixed", mail.content_type assert_equal "multipart/mixed", mail.mime_type assert_equal 2, mail.parts.size - # CHANGED: content_type returns an object - # assert_equal 'text/plain', mail.parts.first.content_type assert_equal 'text/plain', mail.parts.first.mime_type - # CHANGED: body returns an object - # assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s - # CHANGED: content_type returns an object - # assert_equal 'text/html', mail.parts.last.content_type assert_equal 'text/html', mail.parts.last.mime_type - # CHANGED: body returns an object - # assert_equal "Hello from layout text/html multipart", mail.parts.last.body assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s end diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb index 6d0b2c53a3..e49307bfda 100644 --- a/actionmailer/test/old_base/mail_service_test.rb +++ b/actionmailer/test/old_base/mail_service_test.rb @@ -340,6 +340,8 @@ class ActionMailerTest < Test::Unit::TestCase @original_logger = TestMailer.logger @recipient = 'test@localhost' + + TestMailer.delivery_method = :test end def teardown @@ -1191,6 +1193,6 @@ class RespondToTest < Test::Unit::TestCase RespondToMailer.not_a_method end - assert_match(/undefined method.*not_a_method/, error.message) + assert_match(/method.*not_a_method/, error.message) end -end
\ No newline at end of file +end diff --git a/actionmailer/test/old_base/url_test.rb b/actionmailer/test/old_base/url_test.rb index 60740d6b0b..17b383cc2a 100644 --- a/actionmailer/test/old_base/url_test.rb +++ b/actionmailer/test/old_base/url_test.rb @@ -10,7 +10,7 @@ class ActionMailer::Base include AppRoutes.url_helpers end -class TestMailer < ActionMailer::Base +class UrlTestMailer < ActionMailer::Base default_url_options[:host] = 'www.basecamphq.com' configure do |c| @@ -26,14 +26,6 @@ class TestMailer < ActionMailer::Base @recipient = recipient @welcome_url = url_for :host => "example.com", :controller => "welcome", :action => "greeting" end - - class <<self - attr_accessor :received_body - end - - def receive(mail) - self.class.received_body = mail.body - end end class ActionMailerUrlTest < Test::Unit::TestCase @@ -65,7 +57,7 @@ class ActionMailerUrlTest < Test::Unit::TestCase end def test_signed_up_with_url - TestMailer.delivery_method = :test + UrlTestMailer.delivery_method = :test AppRoutes.draw do |map| map.connect ':controller/:action/:id' @@ -80,14 +72,14 @@ class ActionMailerUrlTest < Test::Unit::TestCase expected.date = Time.local(2004, 12, 12) created = nil - assert_nothing_raised { created = TestMailer.signed_up_with_url(@recipient) } + assert_nothing_raised { created = UrlTestMailer.signed_up_with_url(@recipient) } assert_not_nil created expected.message_id = '<123@456>' created.message_id = '<123@456>' assert_equal expected.encoded, created.encoded - assert_nothing_raised { TestMailer.signed_up_with_url(@recipient).deliver } + assert_nothing_raised { UrlTestMailer.signed_up_with_url(@recipient).deliver } assert_not_nil ActionMailer::Base.deliveries.first delivered = ActionMailer::Base.deliveries.first |