aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test/adv_attr_test.rb
blob: f22d733bc5bac0396aa1405eba14739e55784535 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'abstract_unit'
require 'action_mailer/adv_attr_accessor'

class AdvAttrTest < ActiveSupport::TestCase
  class Person
    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
    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

  def test_ivar_is_added_to_protected_instnace_variables
    assert Person.protected_instance_variables.include?('@name')
  end
end