diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-11-24 01:04:44 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-11-24 01:04:44 +0000 |
commit | db045dbbf60b53dbe013ef25554fd013baf88134 (patch) | |
tree | 257830e3c76458c8ff3d1329de83f32b23926028 /actionmailer/test | |
download | rails-db045dbbf60b53dbe013ef25554fd013baf88134.tar.gz rails-db045dbbf60b53dbe013ef25554fd013baf88134.tar.bz2 rails-db045dbbf60b53dbe013ef25554fd013baf88134.zip |
Initial
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/test')
-rw-r--r-- | actionmailer/test/fixtures/templates/signed_up.rhtml | 3 | ||||
-rw-r--r-- | actionmailer/test/fixtures/test_mailer/signed_up.rhtml | 3 | ||||
-rwxr-xr-x | actionmailer/test/mail_service_test.rb | 92 |
3 files changed, 98 insertions, 0 deletions
diff --git a/actionmailer/test/fixtures/templates/signed_up.rhtml b/actionmailer/test/fixtures/templates/signed_up.rhtml new file mode 100644 index 0000000000..a85d5fa442 --- /dev/null +++ b/actionmailer/test/fixtures/templates/signed_up.rhtml @@ -0,0 +1,3 @@ +Hello there, + +Mr. <%= @recipient %>
\ No newline at end of file diff --git a/actionmailer/test/fixtures/test_mailer/signed_up.rhtml b/actionmailer/test/fixtures/test_mailer/signed_up.rhtml new file mode 100644 index 0000000000..a85d5fa442 --- /dev/null +++ b/actionmailer/test/fixtures/test_mailer/signed_up.rhtml @@ -0,0 +1,3 @@ +Hello there, + +Mr. <%= @recipient %>
\ No newline at end of file diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb new file mode 100755 index 0000000000..adc5be2fe9 --- /dev/null +++ b/actionmailer/test/mail_service_test.rb @@ -0,0 +1,92 @@ +$:.unshift(File.dirname(__FILE__) + "/../lib/") + +require 'test/unit' +require 'action_mailer' + +class TestMailer < ActionMailer::Base + def signed_up(recipient) + @recipients = recipient + @subject = "[Signed up] Welcome #{recipient}" + @from = "system@loudthinking.com" + @sent_on = Time.local(2004, 12, 12) + @body["recipient"] = recipient + end + + def cancelled_account(recipient) + @recipients = recipient + @subject = "[Cancelled] Goodbye #{recipient}" + @from = "system@loudthinking.com" + @sent_on = Time.local(2004, 12, 12) + @body = "Goodbye, Mr. #{recipient}" + end +end + +TestMailer.template_root = File.dirname(__FILE__) + "/fixtures" + +class ActionMailerTest < Test::Unit::TestCase + def setup + ActionMailer::Base.delivery_method = :test + ActionMailer::Base.perform_deliveries = true + ActionMailer::Base.deliveries = [] + + @recipient = 'test@localhost' + end + + def test_signed_up + expected = TMail::Mail.new + expected.to = @recipient + expected.subject = "[Signed up] Welcome #{@recipient}" + expected.body = "Hello there, \n\nMr. #{@recipient}" + expected.from = "system@loudthinking.com" + expected.date = Time.local(2004, 12, 12) + + created = nil + assert_nothing_raised { created = TestMailer.create_signed_up(@recipient) } + assert_not_nil created + assert_equal expected.encoded, created.encoded + + assert_nothing_raised { TestMailer.deliver_signed_up(@recipient) } + assert_not_nil ActionMailer::Base.deliveries.first + assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded + end + + def test_cancelled_account + expected = TMail::Mail.new + expected.to = @recipient + expected.subject = "[Cancelled] Goodbye #{@recipient}" + expected.body = "Goodbye, Mr. #{@recipient}" + expected.from = "system@loudthinking.com" + expected.date = Time.local(2004, 12, 12) + + created = nil + assert_nothing_raised { created = TestMailer.create_cancelled_account(@recipient) } + assert_not_nil created + assert_equal expected.encoded, created.encoded + + assert_nothing_raised { TestMailer.deliver_cancelled_account(@recipient) } + assert_not_nil ActionMailer::Base.deliveries.first + assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded + end + + def test_instances_are_nil + assert_nil ActionMailer::Base.new + assert_nil TestMailer.new + end + + def test_deliveries_array + assert_not_nil ActionMailer::Base.deliveries + assert_equal 0, ActionMailer::Base.deliveries.size + TestMailer.deliver_signed_up(@recipient) + assert_equal 1, ActionMailer::Base.deliveries.size + assert_not_nil ActionMailer::Base.deliveries.first + end + + def test_perform_deliveries_flag + ActionMailer::Base.perform_deliveries = false + TestMailer.deliver_signed_up(@recipient) + assert_equal 0, ActionMailer::Base.deliveries.size + ActionMailer::Base.perform_deliveries = true + TestMailer.deliver_signed_up(@recipient) + assert_equal 1, ActionMailer::Base.deliveries.size + end +end |