2009-05-22 14:10:41 -04:00
|
|
|
require 'abstract_unit'
|
2008-01-11 22:06:10 -05:00
|
|
|
require 'action_mailer/adv_attr_accessor'
|
|
|
|
|
2009-12-25 15:35:40 -05:00
|
|
|
class AdvAttrTest < ActiveSupport::TestCase
|
2008-01-11 22:06:10 -05:00
|
|
|
class Person
|
2009-12-25 15:35:40 -05:00
|
|
|
cattr_reader :protected_instance_variables
|
|
|
|
@@protected_instance_variables = []
|
|
|
|
|
|
|
|
extend ActionMailer::AdvAttrAccessor
|
2008-01-11 22:06:10 -05:00
|
|
|
adv_attr_accessor :name
|
|
|
|
end
|
|
|
|
|
2009-12-25 15:35:40 -05:00
|
|
|
def setup
|
|
|
|
@person = Person.new
|
|
|
|
end
|
|
|
|
|
2008-01-11 22:06:10 -05:00
|
|
|
def test_adv_attr
|
2009-12-25 15:35:40 -05:00
|
|
|
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
|
2008-01-11 22:06:10 -05:00
|
|
|
|
2009-12-25 15:35:40 -05:00
|
|
|
def test_ivar_is_added_to_protected_instnace_variables
|
|
|
|
assert Person.protected_instance_variables.include?('@name')
|
2008-01-11 22:06:10 -05:00
|
|
|
end
|
2009-05-22 14:10:41 -04:00
|
|
|
end
|