aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer/test')
-rw-r--r--actionmailer/test/adv_attr_test.rb32
-rw-r--r--actionmailer/test/mail_render_test.rb37
-rw-r--r--actionmailer/test/mail_service_test.rb8
-rw-r--r--actionmailer/test/url_test.rb4
4 files changed, 55 insertions, 26 deletions
diff --git a/actionmailer/test/adv_attr_test.rb b/actionmailer/test/adv_attr_test.rb
index fd909a5627..f22d733bc5 100644
--- a/actionmailer/test/adv_attr_test.rb
+++ b/actionmailer/test/adv_attr_test.rb
@@ -1,18 +1,36 @@
require 'abstract_unit'
require 'action_mailer/adv_attr_accessor'
-class AdvAttrTest < Test::Unit::TestCase
+class AdvAttrTest < ActiveSupport::TestCase
class Person
- include ActionMailer::AdvAttrAccessor
+ cattr_reader :protected_instance_variables
+ @@protected_instance_variables = []
+
+ extend ActionMailer::AdvAttrAccessor
adv_attr_accessor :name
end
+ def setup
+ @person = Person.new
+ end
+
def test_adv_attr
- bob = Person.new
- assert_nil bob.name
- bob.name 'Bob'
- assert_equal 'Bob', bob.name
+ assert_nil @person.name
+ @person.name 'Bob'
+ assert_equal 'Bob', @person.name
+ end
+
+ def test_adv_attr_writer
+ assert_nil @person.name
+ @person.name = 'Bob'
+ assert_equal 'Bob', @person.name
+ end
+
+ def test_raise_an_error_with_multiple_args
+ assert_raise(ArgumentError) { @person.name('x', 'y') }
+ end
- assert_raise(ArgumentError) {bob.name 'x', 'y'}
+ def test_ivar_is_added_to_protected_instnace_variables
+ assert Person.protected_instance_variables.include?('@name')
end
end
diff --git a/actionmailer/test/mail_render_test.rb b/actionmailer/test/mail_render_test.rb
index 047ba0fb41..406aa0a116 100644
--- a/actionmailer/test/mail_render_test.rb
+++ b/actionmailer/test/mail_render_test.rb
@@ -40,13 +40,20 @@ class RenderMailer < ActionMailer::Base
from "tester@example.com"
end
- def included_old_subtemplate(recipient)
+ def mailer_accessor(recipient)
recipients recipient
- subject "Including another template in the one being rendered"
+ subject "Mailer Accessor"
from "tester@example.com"
- @world = "Earth"
- render :inline => "Hello, <%= render \"subtemplate\" %>"
+ render :inline => "Look, <%= mailer.subject %>!"
+ end
+
+ def no_instance_variable(recipient)
+ recipients recipient
+ subject "No Instance Variable"
+ from "tester@example.com"
+
+ render :inline => "Look, subject.nil? is <%= @subject.nil? %>!"
end
def initialize_defaults(method_name)
@@ -71,6 +78,8 @@ class SecondMailer < ActionMailer::Base
end
end
+# CHANGED: Those tests were changed because body returns an object now
+# Instead of mail.body.strip, we should mail.body.to_s.strip
class RenderHelperTest < Test::Unit::TestCase
def setup
set_delivery_method :test
@@ -86,38 +95,38 @@ class RenderHelperTest < Test::Unit::TestCase
def test_implicit_body
mail = RenderMailer.create_implicit_body(@recipient)
- # CHANGED: body returns an object now
- # assert_equal "Hello there, \n\nMr. test@localhost", mail.body.strip
assert_equal "Hello there, \n\nMr. test@localhost", mail.body.to_s.strip
end
def test_inline_template
mail = RenderMailer.create_inline_template(@recipient)
- # CHANGED: body returns an object now
- # assert_equal "Hello, Earth", mail.body.strip
assert_equal "Hello, Earth", mail.body.to_s.strip
end
def test_file_template
mail = RenderMailer.create_file_template(@recipient)
- # CHANGED: body returns an object now
- # assert_equal "Hello there, \n\nMr. test@localhost", mail.body.strip
assert_equal "Hello there, \n\nMr. test@localhost", mail.body.to_s.strip
end
def test_rxml_template
mail = RenderMailer.deliver_rxml_template(@recipient)
- # CHANGED: body returns an object now
- # assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test/>", mail.body.strip
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test/>", mail.body.to_s.strip
end
def test_included_subtemplate
mail = RenderMailer.deliver_included_subtemplate(@recipient)
- # CHANGED: body returns an object now
- # assert_equal "Hey Ho, let's go!", mail.body.strip
assert_equal "Hey Ho, let's go!", mail.body.to_s.strip
end
+
+ def test_mailer_accessor
+ mail = RenderMailer.deliver_mailer_accessor(@recipient)
+ assert_equal "Look, Mailer Accessor!", mail.body.to_s.strip
+ end
+
+ def test_no_instance_variable
+ mail = RenderMailer.deliver_no_instance_variable(@recipient)
+ assert_equal "Look, subject.nil? is true!", mail.body.to_s.strip
+ end
end
class FirstSecondHelperTest < Test::Unit::TestCase
diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb
index 0ea4eda35c..87761185f4 100644
--- a/actionmailer/test/mail_service_test.rb
+++ b/actionmailer/test/mail_service_test.rb
@@ -34,13 +34,13 @@ class TestMailer < ActionMailer::Base
def from_with_name
from "System <system@loudthinking.com>"
recipients "root@loudthinking.com"
- body "Nothing to see here."
+ render :text => "Nothing to see here."
end
def from_without_name
from "system@loudthinking.com"
recipients "root@loudthinking.com"
- body "Nothing to see here."
+ render :text => "Nothing to see here."
end
def cc_bcc(recipient)
@@ -301,6 +301,7 @@ class TestMailer < ActionMailer::Base
render :text => "testing"
end
+ # This tests body calls accepeting a hash, which is deprecated.
def body_ivar(recipient)
recipients recipient
subject "Body as a local variable"
@@ -1119,7 +1120,8 @@ EOF
end
def test_body_is_stored_as_an_ivar
- mail = TestMailer.create_body_ivar(@recipient)
+ mail = nil
+ ActiveSupport::Deprecation.silence { mail = TestMailer.create_body_ivar(@recipient) }
assert_equal "body: foo\nbar: baz", mail.body.to_s
end
diff --git a/actionmailer/test/url_test.rb b/actionmailer/test/url_test.rb
index 6334466a92..12bf609dce 100644
--- a/actionmailer/test/url_test.rb
+++ b/actionmailer/test/url_test.rb
@@ -12,8 +12,8 @@ class TestMailer < ActionMailer::Base
@from = "system@loudthinking.com"
@sent_on = Time.local(2004, 12, 12)
- @body["recipient"] = recipient
- @body["welcome_url"] = url_for :host => "example.com", :controller => "welcome", :action => "greeting"
+ @recipient = recipient
+ @welcome_url = url_for :host => "example.com", :controller => "welcome", :action => "greeting"
end
class <<self