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



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

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



95
96
97
# File 'lib/simple/sql/helpers/immutable.rb', line 95

def immutable
  Immutable.create hsh
end

#test_array_accessObject



118
119
120
121
122
123
124
125
# File 'lib/simple/sql/helpers/immutable.rb', line 118

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



127
128
129
130
131
# File 'lib/simple/sql/helpers/immutable.rb', line 127

def test_base_class
  assert_nothing_raised do
    immutable.object_id
  end
end

#test_child_accessObject



111
112
113
114
115
116
# File 'lib/simple/sql/helpers/immutable.rb', line 111

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



104
105
106
107
108
109
# File 'lib/simple/sql/helpers/immutable.rb', line 104

def test_comparison
  immutable = Immutable.create hsh

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

#test_hash_accessObject



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

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

#test_missing_keysObject



133
134
135
136
137
# File 'lib/simple/sql/helpers/immutable.rb', line 133

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

#test_skip_when_args_or_blockObject



139
140
141
142
143
144
145
146
# File 'lib/simple/sql/helpers/immutable.rb', line 139

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