Class: ODDB::TestPersistence

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_util/persistence.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



140
141
142
143
144
145
146
147
148
149
# File 'test/test_util/persistence.rb', line 140

def setup
  GC.start
  StubPersistenceDiffable.reset_oid
  @obj = StubPersistenceDiffable.new
  #@obj.set_oid
  @obj.foo = 'Foobar'
  @obj.bar = 'Foobar'
  @obj.baz = nil
  @obj.zap = 'Foobar'
end

- (Object) teardown



150
151
152
153
# File 'test/test_util/persistence.rb', line 150

def teardown
  GC.start
  ODBA.storage = nil
end

- (Object) test_diff



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'test/test_util/persistence.rb', line 154

def test_diff
  values = {
    'foo' =>  'Foobar',
    'bar' =>  'Boofar',
    'baz' =>  'Foobaz',
    'zap' =>  nil,
    'date'=>  '01-02-2003',
  }
  expected = {
    'bar' =>  'Boofar',
    'baz' =>  'Foobaz',
    'zap' =>  nil,
    'date'=>  Date.new(2003,02,01),
  }
  assert_equal(nil, @obj.undiffable?("foo"))
  assert_equal(expected, @obj.diff(values.dup))
  obj = StubPersistenceUndiffable.new
  assert_equal(true, @obj.undiffable?(obj))
  @obj.foo = obj
  expected = {
    'foo' =>  'Foobar',
    'bar' =>  'Boofar',
    'baz' =>  'Foobaz',
    'zap' =>  nil,
    'date'=>  Date.new(2003,02,01),
  }
  assert_equal(expected, @obj.diff(values))
end

- (Object) test_nil_if_empty



182
183
184
185
# File 'test/test_util/persistence.rb', line 182

def test_nil_if_empty
  assert_equal(nil, @obj.nil_if_empty(' '))
  assert_equal('foo', @obj.nil_if_empty('foo'))
end

- (Object) test_oid



186
187
188
189
190
191
# File 'test/test_util/persistence.rb', line 186

def test_oid
  obj = StubPersistenceNoOid.new
  # no lazy initializing allowed, since there is no guarantee 
  # for such a value to end up in a snapshot...
  assert_nil(obj.oid)
end

- (Object) test_update_values



192
193
194
195
196
197
198
199
200
201
202
203
# File 'test/test_util/persistence.rb', line 192

def test_update_values
  values = {
    'bar' =>  'Boofar',
    'baz' =>  'Foobaz',
    'zap' =>  nil,
  }
  @obj.update_values(values)
  assert_equal('Foobar', @obj.foo)
  assert_equal('Boofar', @obj.bar)
  assert_equal('Foobaz', @obj.baz)
  assert_equal(nil, @obj.zap)
end