diff options
author | José Valim and Mikel Lindsaar <pair@programming.com> | 2010-01-24 19:52:44 +0100 |
---|---|---|
committer | José Valim and Mikel Lindsaar <pair@programming.com> | 2010-01-24 19:52:50 +0100 |
commit | a74a655648618a6ed568b9b4ef3a17a8970e7774 (patch) | |
tree | 84c1c255aa7b66c35e4303ea934fcf2e40361c8e /actionmailer | |
parent | bd96614101262e0ad0cc176ed8e2d95a5c17936b (diff) | |
download | rails-a74a655648618a6ed568b9b4ef3a17a8970e7774.tar.gz rails-a74a655648618a6ed568b9b4ef3a17a8970e7774.tar.bz2 rails-a74a655648618a6ed568b9b4ef3a17a8970e7774.zip |
Add tests to mail helper.
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 1 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/mail_helper.rb | 4 | ||||
-rw-r--r-- | actionmailer/test/abstract_unit.rb | 1 | ||||
-rw-r--r-- | actionmailer/test/delivery_methods_test.rb | 60 | ||||
-rw-r--r-- | actionmailer/test/fixtures/helper_mailer/use_example_helper.erb | 1 | ||||
-rw-r--r-- | actionmailer/test/fixtures/helper_mailer/use_helper.erb | 1 | ||||
-rw-r--r-- | actionmailer/test/fixtures/helper_mailer/use_helper_method.erb | 1 | ||||
-rw-r--r-- | actionmailer/test/fixtures/helper_mailer/use_mail_helper.erb | 5 | ||||
-rw-r--r-- | actionmailer/test/fixtures/helpers/example_helper.rb | 5 | ||||
-rw-r--r-- | actionmailer/test/mail_helper_test.rb | 54 | ||||
-rw-r--r-- | actionmailer/test/old_base/mail_helper_test.rb | 94 |
11 files changed, 86 insertions, 141 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 1b81cbf5af..7101bfbb70 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -256,7 +256,6 @@ module ActionMailer #:nodoc: include DeliveryMethods, Quoting abstract! - # TODO Add some sanity tests for the included modules include AbstractController::Logger include AbstractController::Rendering include AbstractController::LocalizedCache diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb index 01da954b03..ab5c3469b2 100644 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -17,12 +17,12 @@ module ActionMailer end # Access the mailer instance. - def mailer #:nodoc: + def mailer @_controller end # Access the message instance. - def message #:nodoc: + def message @_message end end diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 781e49ae05..ce09bb5d61 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -19,7 +19,6 @@ 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 -$:.unshift File.join(FIXTURE_LOAD_PATH, 'helpers') class MockSMTP def self.deliveries diff --git a/actionmailer/test/delivery_methods_test.rb b/actionmailer/test/delivery_methods_test.rb index 5b2ce61ca9..145f8ba30d 100644 --- a/actionmailer/test/delivery_methods_test.rb +++ b/actionmailer/test/delivery_methods_test.rb @@ -71,7 +71,7 @@ class CustomDeliveryMethodsTest < ActiveSupport::TestCase end class MailDeliveryTest < ActiveSupport::TestCase - class DeliverMail < ActionMailer::Base + class DeliveryMailer < ActionMailer::Base DEFAULT_HEADERS = { :to => 'mikel@test.lindsaar.net', :from => 'jose@test.plataformatec.com' @@ -87,64 +87,64 @@ class MailDeliveryTest < ActiveSupport::TestCase end def teardown - DeliverMail.delivery_method = :smtp - DeliverMail.perform_deliveries = true - DeliverMail.raise_delivery_errors = true + DeliveryMailer.delivery_method = :smtp + DeliveryMailer.perform_deliveries = true + DeliveryMailer.raise_delivery_errors = true end test "ActionMailer should be told when Mail gets delivered" do - DeliverMail.deliveries.clear - DeliverMail.expects(:delivered_email).once - DeliverMail.welcome.deliver - assert_equal(1, DeliverMail.deliveries.length) + DeliveryMailer.deliveries.clear + DeliveryMailer.expects(:delivered_email).once + DeliveryMailer.welcome.deliver + assert_equal(1, DeliveryMailer.deliveries.length) end test "delivery method can be customized per instance" do - email = DeliverMail.welcome.deliver + email = DeliveryMailer.welcome.deliver assert_instance_of Mail::SMTP, email.delivery_method - email = DeliverMail.welcome(:delivery_method => :test).deliver + email = DeliveryMailer.welcome(:delivery_method => :test).deliver assert_instance_of Mail::TestMailer, email.delivery_method end test "delivery method can be customized in subclasses not changing the parent" do - DeliverMail.delivery_method = :test + DeliveryMailer.delivery_method = :test assert_equal :smtp, ActionMailer::Base.delivery_method $BREAK = true - email = DeliverMail.welcome.deliver + email = DeliveryMailer.welcome.deliver assert_instance_of Mail::TestMailer, email.delivery_method end test "non registered delivery methods raises errors" do - DeliverMail.delivery_method = :unknown + DeliveryMailer.delivery_method = :unknown assert_raise RuntimeError do - DeliverMail.welcome.deliver + DeliveryMailer.welcome.deliver end end test "does not perform deliveries if requested" do - DeliverMail.perform_deliveries = false - DeliverMail.deliveries.clear - DeliverMail.expects(:delivered_email).never - DeliverMail.welcome.deliver - assert_equal(0, DeliverMail.deliveries.length) + DeliveryMailer.perform_deliveries = false + DeliveryMailer.deliveries.clear + DeliveryMailer.expects(:delivered_email).never + DeliveryMailer.welcome.deliver + assert_equal(0, DeliveryMailer.deliveries.length) end test "raise errors on bogus deliveries" do - DeliverMail.delivery_method = BogusDelivery - DeliverMail.deliveries.clear - DeliverMail.expects(:delivered_email).never + DeliveryMailer.delivery_method = BogusDelivery + DeliveryMailer.deliveries.clear + DeliveryMailer.expects(:delivered_email).never assert_raise RuntimeError do - DeliverMail.welcome.deliver + DeliveryMailer.welcome.deliver end - assert_equal(0, DeliverMail.deliveries.length) + assert_equal(0, DeliveryMailer.deliveries.length) end test "does not raise errors on bogus deliveries if set" do - DeliverMail.delivery_method = BogusDelivery - DeliverMail.raise_delivery_errors = false - DeliverMail.deliveries.clear - DeliverMail.expects(:delivered_email).once - DeliverMail.welcome.deliver - assert_equal(1, DeliverMail.deliveries.length) + DeliveryMailer.delivery_method = BogusDelivery + DeliveryMailer.raise_delivery_errors = false + DeliveryMailer.deliveries.clear + DeliveryMailer.expects(:delivered_email).once + DeliveryMailer.welcome.deliver + assert_equal(1, DeliveryMailer.deliveries.length) end end
\ No newline at end of file diff --git a/actionmailer/test/fixtures/helper_mailer/use_example_helper.erb b/actionmailer/test/fixtures/helper_mailer/use_example_helper.erb deleted file mode 100644 index fcff3bb1b4..0000000000 --- a/actionmailer/test/fixtures/helper_mailer/use_example_helper.erb +++ /dev/null @@ -1 +0,0 @@ -So, <%= example_format(@text) %> diff --git a/actionmailer/test/fixtures/helper_mailer/use_helper.erb b/actionmailer/test/fixtures/helper_mailer/use_helper.erb deleted file mode 100644 index 378777f8bb..0000000000 --- a/actionmailer/test/fixtures/helper_mailer/use_helper.erb +++ /dev/null @@ -1 +0,0 @@ -Hello, <%= person_name %>. Thanks for registering! diff --git a/actionmailer/test/fixtures/helper_mailer/use_helper_method.erb b/actionmailer/test/fixtures/helper_mailer/use_helper_method.erb deleted file mode 100644 index d5b8b285e7..0000000000 --- a/actionmailer/test/fixtures/helper_mailer/use_helper_method.erb +++ /dev/null @@ -1 +0,0 @@ -This message brought to you by <%= name_of_the_mailer_class %>. diff --git a/actionmailer/test/fixtures/helper_mailer/use_mail_helper.erb b/actionmailer/test/fixtures/helper_mailer/use_mail_helper.erb deleted file mode 100644 index 96ec49d18a..0000000000 --- a/actionmailer/test/fixtures/helper_mailer/use_mail_helper.erb +++ /dev/null @@ -1,5 +0,0 @@ -From "Romeo and Juliet": - -<%= block_format @text %> - -Good ol' Shakespeare. diff --git a/actionmailer/test/fixtures/helpers/example_helper.rb b/actionmailer/test/fixtures/helpers/example_helper.rb deleted file mode 100644 index f6a6a49ced..0000000000 --- a/actionmailer/test/fixtures/helpers/example_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -module ExampleHelper - def example_format(text) - "<em><strong><small>#{h(text)}</small></strong></em>".html_safe! - end -end diff --git a/actionmailer/test/mail_helper_test.rb b/actionmailer/test/mail_helper_test.rb new file mode 100644 index 0000000000..7cc0804323 --- /dev/null +++ b/actionmailer/test/mail_helper_test.rb @@ -0,0 +1,54 @@ +require 'abstract_unit' + +class HelperMailer < ActionMailer::Base + def use_mail_helper + @text = "But soft! What light through yonder window breaks? It is the east, " + + "and Juliet is the sun. Arise, fair sun, and kill the envious moon, " + + "which is sick and pale with grief that thou, her maid, art far more " + + "fair than she. Be not her maid, for she is envious! Her vestal " + + "livery is but sick and green, and none but fools do wear it. Cast " + + "it off!" + + mail_with_defaults do |format| + format.html { render(:inline => "<%= block_format @text %>") } + end + end + + def use_mailer + mail_with_defaults do |format| + format.html { render(:inline => "<%= mailer.message.subject %>") } + end + end + + def use_message + mail_with_defaults do |format| + format.html { render(:inline => "<%= message.subject %>") } + end + end + + protected + + def mail_with_defaults(&block) + mail(:to => "test@localhost", :from => "tester@example.com", + :subject => "using helpers", &block) + end +end + +class MailerHelperTest < ActionMailer::TestCase + def test_use_mail_helper + mail = HelperMailer.use_mail_helper + assert_match %r{ But soft!}, mail.body.encoded + assert_match %r{east, and\r\n Juliet}, mail.body.encoded + end + + def test_use_mailer + mail = HelperMailer.use_mailer + assert_match "using helpers", mail.body.encoded + end + + def test_use_message + mail = HelperMailer.use_message + assert_match "using helpers", mail.body.encoded + end +end + diff --git a/actionmailer/test/old_base/mail_helper_test.rb b/actionmailer/test/old_base/mail_helper_test.rb deleted file mode 100644 index a9b3cd3ce1..0000000000 --- a/actionmailer/test/old_base/mail_helper_test.rb +++ /dev/null @@ -1,94 +0,0 @@ -require 'abstract_unit' - -module MailerHelper - def person_name - "Mr. Joe Person" - end -end - -class HelperMailer < ActionMailer::Base - helper MailerHelper - helper :example - - def use_helper - recipients 'test@localhost' - subject "using helpers" - from "tester@example.com" - end - - def use_example_helper - recipients 'test@localhost' - subject "using helpers" - from "tester@example.com" - - @text = "emphasize me!" - end - - def use_mail_helper - recipients 'test@localhost' - subject "using mailing helpers" - from "tester@example.com" - - @text = "But soft! What light through yonder window breaks? It is the east, " + - "and Juliet is the sun. Arise, fair sun, and kill the envious moon, " + - "which is sick and pale with grief that thou, her maid, art far more " + - "fair than she. Be not her maid, for she is envious! Her vestal " + - "livery is but sick and green, and none but fools do wear it. Cast " + - "it off!" - end - - def use_helper_method - recipients 'test@localhost' - subject "using helpers" - from "tester@example.com" - - @text = "emphasize me!" - end - - private - - def name_of_the_mailer_class - self.class.name - end - helper_method :name_of_the_mailer_class -end - -class MailerHelperTest < ActiveSupport::TestCase - def new_mail( charset="utf-8" ) - mail = Mail.new - mail.set_content_type "text", "plain", { "charset" => charset } if charset - mail - end - - def setup - set_delivery_method :test - ActionMailer::Base.perform_deliveries = true - ActionMailer::Base.deliveries.clear - end - - def teardown - restore_delivery_method - end - - def test_use_helper - mail = HelperMailer.use_helper - assert_match %r{Mr. Joe Person}, mail.encoded - end - - def test_use_example_helper - mail = HelperMailer.use_example_helper - assert_match %r{<em><strong><small>emphasize me!}, mail.encoded - end - - def test_use_helper_method - mail = HelperMailer.use_helper_method - assert_match %r{HelperMailer}, mail.encoded - end - - def test_use_mail_helper - mail = HelperMailer.use_mail_helper - assert_match %r{ But soft!}, mail.encoded - assert_match %r{east, and\r\n Juliet}, mail.encoded - end -end - |