Class: Simple::SQL::Helpers::Immutable::TestCase

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/simple/sql/helpers/immutable.rb

Constant Summary collapse

Immutable =
::Simple::SQL::Helpers::Immutable

Instance Method Summary collapse

Instance Method Details

#hshObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/simple/sql/helpers/immutable.rb', line 76

def hsh
  {
    a: "a-value",
    "b": "b-value",
    "child": {
      name: "childname",
      grandchild: {
        name: "grandchildname"
      }
    },
    "children": [
      "anna",
      "arthur",
      {
        action: {
          keep_your_mouth_shut: true
        }
      }
    ]
  }
end

#immutableObject



98
99
100
# File 'lib/simple/sql/helpers/immutable.rb', line 98

def immutable
  Immutable.create hsh
end

#test_array_accessObject



121
122
123
124
125
126
127
128
# File 'lib/simple/sql/helpers/immutable.rb', line 121

def test_array_access
  assert_kind_of(Array, immutable.children)
  assert_equal 3, immutable.children.length
  assert_equal "anna", immutable.children[0]

  assert_kind_of(Immutable, immutable.children[2])
  assert_equal true, immutable.children[2].action.keep_your_mouth_shut
end

#test_base_classObject



130
131
132
133
134
# File 'lib/simple/sql/helpers/immutable.rb', line 130

def test_base_class
  assert_nothing_raised do
    immutable.object_id
  end
end

#test_child_accessObject



114
115
116
117
118
119
# File 'lib/simple/sql/helpers/immutable.rb', line 114

def test_child_access
  child = immutable.child
  assert_kind_of(Immutable, child)
  assert_equal "childname", immutable.child.name
  assert_equal "grandchildname", immutable.child.grandchild.name
end

#test_comparisonObject



107
108
109
110
111
112
# File 'lib/simple/sql/helpers/immutable.rb', line 107

def test_comparison
  immutable = Immutable.create hsh

  assert_equal immutable, hsh
  assert_not_equal({}, immutable)
end

#test_hash_accessObject



102
103
104
105
# File 'lib/simple/sql/helpers/immutable.rb', line 102

def test_hash_access
  assert_equal "a-value", immutable.a
  assert_equal "b-value", immutable.b
end

#test_missing_keysObject



136
137
138
139
140
# File 'lib/simple/sql/helpers/immutable.rb', line 136

def test_missing_keys
  assert_raise(NoMethodError) do
    immutable.foo
  end
end

#test_skip_when_args_or_blockObject



142
143
144
145
146
147
148
149
# File 'lib/simple/sql/helpers/immutable.rb', line 142

def test_skip_when_args_or_block
  assert_raise(NoMethodError) do
    immutable.a(1, 2, 3)
  end
  assert_raise(NoMethodError) do
    immutable.a { :dummy }
  end
end