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.rb25
2 files changed, 46 insertions, 11 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 514f7ed798..0e38a0caba 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)
@@ -108,6 +115,16 @@ class RenderHelperTest < Test::Unit::TestCase
mail = RenderMailer.deliver_included_subtemplate(@recipient)
assert_equal "Hey Ho, let's go!", mail.body.strip
end
+
+ def test_mailer_accessor
+ mail = RenderMailer.deliver_mailer_accessor(@recipient)
+ assert_equal "Look, Mailer Accessor!", mail.body.strip
+ end
+
+ def test_no_instance_variable
+ mail = RenderMailer.deliver_no_instance_variable(@recipient)
+ assert_equal "Look, subject.nil? is true!", mail.body.strip
+ end
end
class FirstSecondHelperTest < Test::Unit::TestCase