odba 1.1.8 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,545 +1,553 @@
1
1
  #!/usr/bin/env ruby
2
2
  # TestPersistable -- odba -- ??.??.???? -- hwyss@ywesee.com
3
-
4
- $: << File.dirname(__FILE__)
5
- $: << File.expand_path('../lib/', File.dirname(__FILE__))
6
-
7
- require 'minitest/autorun'
8
- require 'flexmock/test_unit'
9
- require 'flexmock'
10
- require 'odba/persistable'
11
- require 'odba/stub'
12
- require 'odba/cache'
13
- require 'odba/odba'
14
- require 'odba/storage'
15
- require 'odba/marshal'
16
- require 'yaml'
3
+ require_relative "helper"
4
+ require "odba/persistable"
5
+ require "odba/storage"
6
+ require "odba/cache"
7
+ require "odba/odba"
8
+ require "odba/marshal"
17
9
 
18
10
  module ODBA
19
- module Persistable
20
- attr_accessor :odba_references
21
- attr_writer :odba_id
22
- public :odba_replace_excluded!
23
- end
24
- class TestPersistable < Minitest::Test
11
+ module Persistable
12
+ attr_accessor :odba_references
13
+ attr_writer :odba_id
14
+ public :odba_replace_excluded!
15
+ end
16
+
17
+ class TestPersistable < Test::Unit::TestCase
25
18
  include FlexMock::TestCase
26
- class ODBAExcluding
27
- include ODBA::Persistable
28
- ODBA_EXCLUDE_VARS = ["@excluded"]
29
- attr_accessor :included, :excluded
30
- end
31
- class ODBAContainerInPersistable
32
- include ODBA::Persistable
33
- ODBA_SERIALIZABLE = ['@serializable']
34
- attr_accessor :non_replaceable, :replaceable, :replaceable2,
35
- :array, :odba_persistent, :serializable
36
- attr_accessor :odba_snapshot_level
37
- end
38
- class Hash
39
- include ODBA::Persistable
40
- attr_accessor :odba_persistent
41
- end
19
+ class ODBAExcluding
20
+ include ODBA::Persistable
21
+ ODBA_EXCLUDE_VARS = ["@excluded"]
22
+ attr_accessor :included, :excluded
23
+ end
24
+
25
+ class ODBAContainerInPersistable
26
+ include ODBA::Persistable
27
+ ODBA_SERIALIZABLE = ["@serializable"]
28
+ attr_accessor :non_replaceable, :replaceable, :replaceable2,
29
+ :array, :odba_persistent, :serializable
30
+ attr_accessor :odba_snapshot_level
31
+ end
32
+
33
+ class Hash
34
+ include ODBA::Persistable
35
+ attr_accessor :odba_persistent
36
+ end
37
+
42
38
  class IndexedStub
43
39
  include Persistable
44
- #attr_accessor :origin
40
+ # attr_accessor :origin
45
41
  odba_index :name
46
42
  odba_index :foo, :bar
47
43
  odba_index :origin, :origin, :non_replaceable, ODBAContainerInPersistable
48
- odba_index :redirect, 'redirect.name'
49
- end
50
- def setup
51
- ODBA.storage = flexmock("storage")
52
- ODBA.marshaller = flexmock("marshaller_persistable")
53
- ODBA.cache = flexmock("cache")
54
- @odba = ODBAContainerInPersistable.new
55
- end
56
- def teardown
57
- ODBA.storage.flexmock_verify
58
- ODBA.marshaller.flexmock_verify
59
- ODBA.cache.flexmock_verify
60
- ODBA.storage = nil
61
- ODBA.marshaller = nil
62
- ODBA.cache = nil
44
+ odba_index :redirect, "redirect.name"
45
+ end
46
+
47
+ def setup
48
+ ODBA.storage = flexmock("storage")
49
+ ODBA.marshaller = flexmock("marshaller_persistable")
50
+ ODBA.cache = flexmock("cache")
51
+ @odba = ODBAContainerInPersistable.new
52
+ end
53
+
54
+ def teardown
55
+ ODBA.storage.flexmock_verify
56
+ ODBA.marshaller.flexmock_verify
57
+ ODBA.cache.flexmock_verify
58
+ ODBA.storage = nil
59
+ ODBA.marshaller = nil
60
+ ODBA.cache = nil
63
61
  super
64
- end
65
- def test_odba_id
66
- DBA.cache.should_receive(:next_id).with().and_return(2)
67
- ODBA.marshaller.should_receive(:dump).and_return('foo')
68
- ODBA.storage.should_receive(:store)
69
- @odba.odba_take_snapshot(1)
70
- assert_equal(2, @odba.odba_id)
71
- ODBA.storage.flexmock_verify
72
- ODBA.marshaller.flexmock_verify
73
- end
74
- def test_odba_delete
75
- odba_container = ODBAContainerInPersistable.new
76
- odba_container.odba_id = 2
62
+ end
63
+
64
+ def test_odba_delete
65
+ odba_container = ODBAContainerInPersistable.new
66
+ odba_container.odba_id = 2
77
67
  ODBA.cache.should_receive(:delete).with(odba_container)
78
- odba_container.odba_delete
79
- end
80
- def test_odba_replace_excluded
81
- odba = ODBAExcluding.new
82
- odba.included = "here to stay"
83
- odba.excluded = "easy come easy go"
84
- odba.odba_replace_excluded!
85
- assert_equal("here to stay", odba.included)
86
- assert_nil(odba.excluded)
87
- end
88
- def test_odba_replace_stubs
89
- stub = flexmock
68
+ odba_container.odba_delete
69
+ end
70
+
71
+ def test_odba_replace_excluded
72
+ odba = ODBAExcluding.new
73
+ odba.included = "here to stay"
74
+ odba.excluded = "easy come easy go"
75
+ odba.odba_replace_excluded!
76
+ assert_equal("here to stay", odba.included)
77
+ assert_nil(odba.excluded)
78
+ end
79
+
80
+ def test_odba_replace_stubs
81
+ stub = flexmock
90
82
  stub.should_receive(:odba_id).and_return(6)
91
83
  stub.should_receive(:is_a?).with(Stub).and_return(true)
92
- @odba.replaceable = stub
93
- substitution = flexmock
84
+ @odba.replaceable = stub
85
+ substitution = flexmock
94
86
  substitution.should_receive(:odba_id).and_return(6)
95
- @odba.odba_replace_stubs(6, substitution)
96
- assert_equal(@odba.replaceable, substitution)
97
- end
98
- def test_odba_take_snapshot
99
- level1 = ODBAContainerInPersistable.new
100
- level2 = ODBAContainerInPersistable.new
101
- @odba.replaceable = level1
102
- level1.replaceable = level2
87
+ @odba.odba_replace_stubs(6, substitution)
88
+ assert_equal(@odba.replaceable, substitution)
89
+ end
90
+
91
+ def test_odba_take_snapshot
92
+ level1 = ODBAContainerInPersistable.new
93
+ level2 = ODBAContainerInPersistable.new
94
+ @odba.replaceable = level1
95
+ level1.replaceable = level2
103
96
  ODBA.cache.should_receive(:store).with(FlexMock.any).times(3).and_return(2)
104
- @odba.odba_take_snapshot
105
- assert_equal(1, @odba.odba_snapshot_level)
106
- assert_equal(1, level1.odba_snapshot_level)
107
- assert_equal(1, level2.odba_snapshot_level)
108
- ODBA.cache.flexmock_verify
109
- end
110
- def test_odba_unsaved_neighbors
111
- replaceable = flexmock
112
- @odba.replaceable = replaceable
97
+ @odba.odba_take_snapshot
98
+ assert_equal(1, @odba.odba_snapshot_level)
99
+ assert_equal(1, level1.odba_snapshot_level)
100
+ assert_equal(1, level2.odba_snapshot_level)
101
+ ODBA.cache.flexmock_verify
102
+ end
103
+
104
+ def test_odba_unsaved_neighbors
105
+ replaceable = flexmock
106
+ @odba.replaceable = replaceable
113
107
  replaceable.should_receive(:is_a?).with(Persistable).and_return(true)
114
108
  replaceable.should_receive(:odba_unsaved?).with(FlexMock.any).and_return(true)
115
- result = @odba.odba_unsaved_neighbors(2)
116
- assert_equal([replaceable], result)
117
- replaceable.flexmock_verify
118
- end
119
- def test_odba_unsaved_neighbors_2
120
- odba = ODBAExcluding.new
121
- included = flexmock
122
- excluded = flexmock
123
- odba.excluded = excluded
124
- odba.included = included
109
+ result = @odba.odba_unsaved_neighbors(2)
110
+ assert_equal([replaceable], result)
111
+ replaceable.flexmock_verify
112
+ end
113
+
114
+ def test_odba_unsaved_neighbors_2
115
+ odba = ODBAExcluding.new
116
+ included = flexmock
117
+ excluded = flexmock
118
+ odba.excluded = excluded
119
+ odba.included = included
125
120
  included.should_receive(:is_a?).with(Persistable).and_return(true)
126
121
  included.should_receive(:odba_unsaved?).with(FlexMock.any).and_return(true)
127
- result = odba.odba_unsaved_neighbors(2)
128
- assert_equal([included], result)
129
- excluded.flexmock_verify
130
- included.flexmock_verify
131
- end
132
- def test_extend_enumerable
133
- hash = Hash.new
134
- array = Array.new
135
- assert_equal(true, hash.is_a?(Persistable))
136
- assert_equal(true, array.is_a?(Persistable))
137
- end
138
- def test_odba_stubize
139
- replaceable = ODBAContainerInPersistable.new
140
- non_rep = ODBAContainerInPersistable.new
141
- non_rep.odba_id = 32
142
- replaceable.odba_id = 24
143
- @odba.replaceable = replaceable
144
- @odba.non_replaceable = non_rep
145
- @odba.odba_stubize(replaceable)
146
- assert_equal(24, @odba.replaceable.odba_id)
147
- assert_equal(true, @odba.replaceable.is_a?(Stub))
148
- assert_equal(true, @odba.non_replaceable.is_a?(ODBAContainerInPersistable))
149
- end
150
- def test_odba_replace_persistables
151
- replaceable = ODBAContainerInPersistable.new
152
- replaceable.odba_id = 12
153
- non_replaceable = flexmock
154
- @odba.non_replaceable = non_replaceable
155
- @odba.replaceable = replaceable
156
- non_replaceable.should_receive(:is_a?).with(Stub)\
122
+ result = odba.odba_unsaved_neighbors(2)
123
+ assert_equal([included], result)
124
+ excluded.flexmock_verify
125
+ included.flexmock_verify
126
+ end
127
+
128
+ def test_extend_enumerable
129
+ hash = {}
130
+ array = []
131
+ assert_equal(true, hash.is_a?(Persistable))
132
+ assert_equal(true, array.is_a?(Persistable))
133
+ end
134
+
135
+ def test_odba_stubize
136
+ replaceable = ODBAContainerInPersistable.new
137
+ non_rep = ODBAContainerInPersistable.new
138
+ non_rep.odba_id = 32
139
+ replaceable.odba_id = 24
140
+ @odba.replaceable = replaceable
141
+ @odba.non_replaceable = non_rep
142
+ @odba.odba_stubize(replaceable)
143
+ assert_equal(24, @odba.replaceable.odba_id)
144
+ assert_equal(true, @odba.replaceable.is_a?(Stub))
145
+ assert_equal(true, @odba.non_replaceable.is_a?(ODBAContainerInPersistable))
146
+ end
147
+
148
+ def test_odba_replace_persistables
149
+ replaceable = ODBAContainerInPersistable.new
150
+ replaceable.odba_id = 12
151
+ non_replaceable = flexmock
152
+ @odba.non_replaceable = non_replaceable
153
+ @odba.replaceable = replaceable
154
+ non_replaceable.should_receive(:is_a?).with(Stub)
157
155
  .times(1).and_return(false)
158
- non_replaceable.should_receive(:is_a?).with(Persistable)\
156
+ non_replaceable.should_receive(:is_a?).with(Persistable)
159
157
  .times(1).and_return(false)
160
- @odba.odba_replace_persistables
161
- assert_instance_of(FlexMock, @odba.non_replaceable)
162
- assert_equal(12, @odba.replaceable.odba_id)
163
- assert_equal(true, @odba.replaceable.is_a?(Stub))
164
- non_replaceable.flexmock_verify
165
- ODBA.cache.flexmock_verify
166
- end
167
- def test_odba_replace_persistables__stubised_serialisable
168
- non_replaceable = flexmock
169
- @odba.serializable = non_replaceable
158
+ @odba.odba_replace_persistables
159
+ assert_instance_of(FlexMock, @odba.non_replaceable)
160
+ assert_equal(12, @odba.replaceable.odba_id)
161
+ assert_equal(true, @odba.replaceable.is_a?(Stub))
162
+ non_replaceable.flexmock_verify
163
+ ODBA.cache.flexmock_verify
164
+ end
165
+
166
+ def test_odba_replace_persistables__stubised_serialisable
167
+ non_replaceable = flexmock
168
+ @odba.serializable = non_replaceable
170
169
  non_replaceable.should_receive(:is_a?).with(Stub).and_return(true)
171
- non_replaceable.should_receive(:odba_instance).and_return('serialize this')
172
- @odba.odba_replace_persistables
173
- assert_equal('serialize this', @odba.serializable)
174
- non_replaceable.flexmock_verify
175
- end
176
- def test_odba_store_unsaved
177
- level1 = ODBAContainerInPersistable.new
178
- level2 = ODBAContainerInPersistable.new
179
- saved = ODBAContainerInPersistable.new
180
- @odba.replaceable = level1
181
- @odba.non_replaceable = saved
182
- level1.replaceable = level2
183
-
184
- saved.odba_persistent = true
185
- ODBA.cache.should_receive(:store).times(3).and_return {
170
+ non_replaceable.should_receive(:odba_instance).and_return("serialize this")
171
+ @odba.odba_replace_persistables
172
+ assert_equal("serialize this", @odba.serializable)
173
+ non_replaceable.flexmock_verify
174
+ end
175
+
176
+ def test_odba_store_unsaved
177
+ level1 = ODBAContainerInPersistable.new
178
+ level2 = ODBAContainerInPersistable.new
179
+ saved = ODBAContainerInPersistable.new
180
+ @odba.replaceable = level1
181
+ @odba.non_replaceable = saved
182
+ level1.replaceable = level2
183
+
184
+ saved.odba_persistent = true
185
+ ODBA.cache.should_receive(:store).times(3).and_return {
186
186
  assert(true)
187
187
  2
188
188
  }
189
189
 
190
- @odba.odba_store_unsaved
191
- end
192
- def test_odba_store_unsaved_hash
193
- level1 = ODBAContainerInPersistable.new
194
- hash_element = ODBAContainerInPersistable.new
195
- hash = Hash.new
196
- non_rep_hash = Hash.new
197
- level1.replaceable = hash
198
- level1.non_replaceable = non_rep_hash
199
- non_rep_hash.odba_persistent = true
200
-
201
- ODBA.cache.should_receive(:store).times(2).and_return {
190
+ @odba.odba_store_unsaved
191
+ end
192
+
193
+ def test_odba_store_unsaved_hash
194
+ level1 = ODBAContainerInPersistable.new
195
+ ODBAContainerInPersistable.new
196
+ hash = {}
197
+ non_rep_hash = {}
198
+ level1.replaceable = hash
199
+ level1.non_replaceable = non_rep_hash
200
+ non_rep_hash.odba_persistent = true
201
+
202
+ ODBA.cache.should_receive(:store).times(2).and_return {
202
203
  assert(true)
203
204
  2
204
205
  }
205
206
 
206
- level1.odba_store_unsaved
207
- end
207
+ level1.odba_store_unsaved
208
+ end
209
+
208
210
  def test_dup
209
211
  twin = @odba.dup
210
- assert_nil(twin.instance_variable_get('@odba_id'))
211
- end
212
- def test_odba_dup
213
- stub = flexmock("stub")
214
- stub2 = flexmock("stub2")
215
- @odba.replaceable = stub
216
- @odba.replaceable2 = stub2
217
- @odba.non_replaceable = 4
218
- stub.should_receive(:is_a?).with_no_args.and_return(true)
219
- stub.should_receive(:odba_dup).with_no_args.and_return(stub)
220
- stub_container = nil
221
- stub.should_receive(:odba_container=).with_no_args.and_return(stub_container)
222
- stub2.should_receive(:is_a?).with_no_args.and_return(true)
223
- stub2.should_receive(:odba_dup).with_no_args.and_return(stub2)
224
- stub_container2 = nil
225
- stub2.should_receive(:odba_container=).with_no_args.and_return(stub_container2)
226
- odba_twin = @odba.odba_dup
227
- odba_twin.replaceable.flexmock_verify
228
- odba_twin.replaceable2.flexmock_verify
229
- assert_equal(odba_twin, stub_container)
230
- assert_equal(odba_twin, stub_container2)
231
- end
232
- def test_odba_unsaved_true
233
- @odba.instance_variable_set("@odba_persistent", false)
234
- assert_equal(true, @odba.odba_unsaved?)
235
- end
236
- def test_odba_target_ids
237
- replaceable = flexmock("rep")
238
- replaceable2 = flexmock("rep2")
239
- @odba.replaceable = replaceable
240
- @odba.replaceable2 = replaceable2
212
+ assert_nil(twin.instance_variable_get(:@odba_id))
213
+ end
214
+
215
+ def test_odba_unsaved_true
216
+ @odba.instance_variable_set(:@odba_persistent, false)
217
+ assert_equal(true, @odba.odba_unsaved?)
218
+ end
219
+
220
+ def test_odba_target_ids
221
+ replaceable = flexmock("rep")
222
+ replaceable2 = flexmock("rep2")
223
+ @odba.replaceable = replaceable
224
+ @odba.replaceable2 = replaceable2
241
225
  replaceable.should_receive(:is_a?).with(ODBA::Persistable).and_return(true)
242
226
  replaceable.should_receive(:odba_id).with_no_args.and_return(12)
243
227
  replaceable2.should_receive(:is_a?).with(ODBA::Persistable).and_return(false)
244
- expected = [12]
245
- assert_equal(expected, @odba.odba_target_ids.sort)
246
- replaceable.flexmock_verify
247
- replaceable2.flexmock_verify
248
- end
249
- def test_odba_isolated_dump
250
- replaceable = flexmock("Replaceable")
251
- replaceable2 = flexmock("Replaceable2")
252
- @odba.replaceable = replaceable
253
- @odba.replaceable2 = replaceable2
228
+ expected = [12]
229
+ assert_equal(expected, @odba.odba_target_ids.sort)
230
+ replaceable.flexmock_verify
231
+ replaceable2.flexmock_verify
232
+ end
233
+
234
+ def test_odba_isolated_dump
235
+ replaceable = flexmock("Replaceable")
236
+ replaceable2 = flexmock("Replaceable2")
237
+ @odba.replaceable = replaceable
238
+ @odba.replaceable2 = replaceable2
254
239
  ODBA.cache.should_receive(:next_id).with_no_args.and_return(11)
255
240
 
256
241
  ### from odba_dup and odba_replace_persistables
257
- replaceable2.should_receive(:is_a?).with(Stub)\
242
+ replaceable2.should_receive(:is_a?).with(Stub)
258
243
  .times(2).and_return(false)
259
- replaceable2.should_receive(:is_a?).with(Persistable)\
244
+ replaceable2.should_receive(:is_a?).with(Persistable)
260
245
  .times(1).and_return(true)
261
- replaceable2.should_receive(:odba_id).times(1).and_return(12)
246
+ replaceable2.should_receive(:odba_id).times(1).and_return(12)
262
247
 
263
248
  ### from odba_dup
264
249
  responses = [false, true]
265
- replaceable.should_receive(:is_a?).with(Stub)\
250
+ replaceable.should_receive(:is_a?).with(Stub)
266
251
  .times(2).and_return { responses.shift }
267
252
  replaceable.should_receive(:odba_clear_receiver).times(1)
268
- replaceable.should_receive(:odba_container=).with(@odba.class).times(1)
269
- ODBA.marshaller.should_receive(:dump).and_return{ |twin| assert(twin.replaceable2.is_a?(ODBA::Stub)); "TheDump" }
270
- result = @odba.odba_isolated_dump
271
- assert_equal(replaceable, @odba.replaceable)
272
- assert_equal(replaceable2, @odba.replaceable2)
273
- assert_equal("TheDump", result)
274
- replaceable.flexmock_verify
275
- replaceable2.flexmock_verify
276
- end
277
- def test_odba_isolated_dump_2
278
- tmp = ODBA.marshaller
279
- ODBA.marshaller = ODBA::Marshal
280
- odba = ODBAExcluding.new
281
- odba.excluded = "foo"
282
- odba.included = "baz"
253
+ replaceable.should_receive(:odba_container=).with(@odba.class).times(1)
254
+ ODBA.marshaller.should_receive(:dump).and_return { |twin|
255
+ assert(twin.replaceable2.is_a?(ODBA::Stub))
256
+ "TheDump"
257
+ }
258
+ result = @odba.odba_isolated_dump
259
+ assert_equal(replaceable, @odba.replaceable)
260
+ assert_equal(replaceable2, @odba.replaceable2)
261
+ assert_equal("TheDump", result)
262
+ replaceable.flexmock_verify
263
+ replaceable2.flexmock_verify
264
+ end
265
+
266
+ def test_odba_isolated_dump_2
267
+ tmp = ODBA.marshaller
268
+ ODBA.marshaller = ODBA::Marshal
269
+ odba = ODBAExcluding.new
270
+ odba.excluded = "foo"
271
+ odba.included = "baz"
283
272
  ODBA.cache.should_receive(:next_id).and_return(1)
284
- dump, hash = odba.odba_isolated_dump
285
- obj = ODBA.marshaller.load(dump)
286
- assert_nil(obj.excluded)
287
- assert_equal("baz", obj.included)
288
- ODBA.marshaller = tmp
289
- end
290
- def test_odba_id
291
- @odba.odba_id = nil
273
+ dump, _ = odba.odba_isolated_dump
274
+ obj = ODBA.marshaller.load(dump)
275
+ assert_nil(obj.excluded)
276
+ assert_equal("baz", obj.included)
277
+ ODBA.marshaller = tmp
278
+ end
279
+
280
+ def test_odba_id
281
+ @odba.odba_id = nil
292
282
  ODBA.cache.should_receive(:next_id).and_return(1)
293
- assert_equal(1, @odba.odba_id)
294
- ODBA.storage.flexmock_verify
295
- end
296
- def test_odba_dump_has_id
297
- @odba.odba_id = nil
283
+ assert_equal(1, @odba.odba_id)
284
+ ODBA.storage.flexmock_verify
285
+ end
286
+
287
+ def test_odba_dump_has_id
288
+ @odba.odba_id = nil
298
289
  ODBA.cache.should_receive(:store).with(FlexMock.any)
299
290
  ODBA.cache.should_receive(:next_id).with(1).and_return(1)
300
- @odba.odba_store
301
- end
302
- def test_odba_store_error_raised
303
- @odba.odba_name = "foo"
291
+ @odba.odba_store
292
+ end
293
+
294
+ def test_odba_store_error_raised
295
+ @odba.odba_name = "foo"
304
296
  ODBA.cache.should_receive(:store).with(FlexMock.any).and_return { |dump|
305
- raise DBI::ProgrammingError
306
- }
307
- assert_raises(DBI::ProgrammingError) {
308
- @odba.odba_store('baz')
309
- }
310
- assert_equal("foo", @odba.odba_name)
311
- end
312
- def test_odba_store_no_error_raised
313
- @odba.odba_name = "foo"
297
+ raise DBI::ProgrammingError
298
+ }
299
+ assert_raises(DBI::ProgrammingError) {
300
+ @odba.odba_store("baz")
301
+ }
302
+ assert_equal("foo", @odba.odba_name)
303
+ end
304
+
305
+ def test_odba_store_no_error_raised
306
+ @odba.odba_name = "foo"
314
307
  ODBA.cache.should_receive(:store).with(@odba)
315
- @odba.odba_store('bar')
316
- assert_equal("bar", @odba.odba_name)
317
- end
318
- def test_inspect_with_stub_in_array
308
+ @odba.odba_store("bar")
309
+ assert_equal("bar", @odba.odba_name)
310
+ end
311
+
312
+ def test_inspect_with_stub_in_array
319
313
  ODBA.cache.should_receive(:next_id).with_no_args.and_return(12)
320
314
  ODBA.cache.should_receive(:next_id).with_no_args.and_return(13)
321
- content = ODBAContainerInPersistable.new
322
- @odba.instance_variable_set('@contents', [content])
323
- twin = @odba.odba_isolated_twin
324
- refute_nil(/@contents=#<ODBA::Stub:/.match(twin.inspect))
325
- ODBA.storage.flexmock_verify
326
- end
327
- def test_to_yaml
328
- yaml = ''
315
+ content = ODBAContainerInPersistable.new
316
+ @odba.instance_variable_set(:@contents, [content])
317
+ twin = @odba.odba_isolated_twin
318
+ refute_nil(/@contents=#<ODBA::Stub:/.match(twin.inspect))
319
+ ODBA.storage.flexmock_verify
320
+ end
321
+
322
+ def test_to_yaml
329
323
  yaml = @odba.to_yaml
330
- loaded = YAML.load(yaml)
331
- assert_instance_of(ODBAContainerInPersistable, loaded)
332
- end
324
+ loaded = YAML.safe_load(yaml, permitted_classes: [ODBA::TestPersistable::ODBAContainerInPersistable])
325
+ assert_instance_of(ODBAContainerInPersistable, loaded)
326
+ end
327
+
333
328
  def test_extend
334
- ODBA.cache.should_receive(:store).with('foo')
335
- str = 'foo'
329
+ ODBA.cache.should_receive(:store).with("foo")
330
+ str = "foo"
336
331
  str.extend(Persistable)
337
332
  str.odba_store
338
333
  ODBA.cache.flexmock_verify
339
334
  end
335
+
340
336
  def test_odba_index__simple
341
337
  stub = IndexedStub.new
342
338
  assert_respond_to(stub, :name)
343
339
  assert_respond_to(stub, :name=)
344
340
  assert_respond_to(IndexedStub, :find_by_name)
345
- result = flexmock('Result')
341
+ result = flexmock("Result")
346
342
 
347
343
  ## search by one key
348
- name = 'odba_testpersistable_indexedstub_name'
349
- args = 'xan'
350
- ODBA.cache.should_receive(:retrieve_from_index).with(name, args)\
344
+ name = "odba_testpersistable_indexedstub_name"
345
+ args = "xan"
346
+ ODBA.cache.should_receive(:retrieve_from_index).with(name, args)
351
347
  .times(1).and_return([result])
352
- assert_equal([result], IndexedStub.search_by_name('xan'))
348
+ assert_equal([result], IndexedStub.search_by_name("xan"))
353
349
 
354
350
  ## exact search by one key
355
- ODBA.cache.should_receive(:retrieve_from_index)\
356
- .with(name, args, ODBA::Persistable::Exact)\
351
+ ODBA.cache.should_receive(:retrieve_from_index)
352
+ .with(name, args, ODBA::Persistable::Exact)
357
353
  .times(1).and_return([result])
358
- assert_equal([result], IndexedStub.search_by_exact_name('xan'))
354
+ assert_equal([result], IndexedStub.search_by_exact_name("xan"))
359
355
 
360
356
  ## find by one key
361
- ODBA.cache.should_receive(:retrieve_from_index)\
362
- .with(name, args, ODBA::Persistable::Find)\
357
+ ODBA.cache.should_receive(:retrieve_from_index)
358
+ .with(name, args, ODBA::Persistable::Find)
363
359
  .times(1).and_return([result])
364
- assert_equal(result, IndexedStub.find_by_name('xan'))
360
+ assert_equal(result, IndexedStub.find_by_name("xan"))
365
361
 
366
362
  ## list available keys
367
- ODBA.cache.should_receive(:index_keys).with(name, nil)\
368
- .times(1).and_return(['key1', 'key2'])
369
- assert_equal(['key1', 'key2'], IndexedStub.name_keys)
370
- ODBA.cache.should_receive(:index_keys).with(name, 2)\
371
- .times(1).and_return(['k1', 'k2'])
372
- assert_equal(['k1', 'k2'], IndexedStub.name_keys(2))
363
+ ODBA.cache.should_receive(:index_keys).with(name, nil)
364
+ .times(1).and_return(["key1", "key2"])
365
+ assert_equal(["key1", "key2"], IndexedStub.name_keys)
366
+ ODBA.cache.should_receive(:index_keys).with(name, 2)
367
+ .times(1).and_return(["k1", "k2"])
368
+ assert_equal(["k1", "k2"], IndexedStub.name_keys(2))
373
369
  end
370
+
374
371
  def test_odba_index__multikey
375
372
  stub = IndexedStub.new
376
373
  assert_respond_to(stub, :foo)
377
374
  assert_respond_to(stub, :bar)
378
375
  assert_respond_to(IndexedStub, :find_by_foo_and_bar)
379
- result = flexmock('Result')
376
+ result = flexmock("Result")
380
377
 
381
378
  ## search by multiple keys
382
- name = 'odba_testpersistable_indexedstub_foo_and_bar'
379
+ name = "odba_testpersistable_indexedstub_foo_and_bar"
383
380
  args = {
384
- :foo => { 'condition' => 'like', 'value' => 'oof'},
385
- :bar => { 'condition' => 'like', 'value' => 'rab'},
381
+ foo: {"condition" => "like", "value" => "oof"},
382
+ bar: {"condition" => "like", "value" => "rab"}
386
383
  }
387
- ODBA.cache.should_receive(:retrieve_from_index).with(name, args)\
384
+ ODBA.cache.should_receive(:retrieve_from_index).with(name, args)
388
385
  .times(1).and_return([result])
389
386
  assert_equal([result],
390
- IndexedStub.search_by_foo_and_bar('oof', 'rab'))
387
+ IndexedStub.search_by_foo_and_bar("oof", "rab"))
391
388
 
392
389
  ## exact search by multiple keys
393
- args = {:foo => 'oof', :bar => 'rab'}
394
- ODBA.cache.should_receive(:retrieve_from_index)\
395
- .with(name, args, Persistable::Exact)\
390
+ args = {foo: "oof", bar: "rab"}
391
+ ODBA.cache.should_receive(:retrieve_from_index)
392
+ .with(name, args, Persistable::Exact)
396
393
  .times(1).and_return([result])
397
394
  assert_equal([result],
398
- IndexedStub.search_by_exact_foo_and_bar('oof', 'rab'))
395
+ IndexedStub.search_by_exact_foo_and_bar("oof", "rab"))
399
396
 
400
397
  ## find by multiple keys
401
- args = {:foo => {'value' => 7,'condition' => '='},
402
- :bar => {'value' => 'rab','condition' => 'like'}}
403
- ODBA.cache.should_receive(:retrieve_from_index)\
404
- .with(name, args, Persistable::Find)\
398
+ args = {foo: {"value" => 7, "condition" => "="},
399
+ bar: {"value" => "rab", "condition" => "like"}}
400
+ ODBA.cache.should_receive(:retrieve_from_index)
401
+ .with(name, args, Persistable::Find)
405
402
  .times(1).and_return([result])
406
- assert_equal(result, IndexedStub.find_by_foo_and_bar(7, 'rab'))
403
+ assert_equal(result, IndexedStub.find_by_foo_and_bar(7, "rab"))
407
404
  end
405
+
408
406
  def test_odba_index__directional
409
407
  stub = IndexedStub.new
410
408
  assert_respond_to(stub, :origin)
411
409
  assert_respond_to(stub, :origin=)
412
410
  assert_respond_to(IndexedStub, :find_by_origin)
413
- result = flexmock('Result')
411
+ result = flexmock("Result")
414
412
 
415
413
  ## search by one key
416
- name = 'odba_testpersistable_indexedstub_origin'
417
- args = 'xan'
418
- ODBA.cache.should_receive(:retrieve_from_index).with(name, args)\
414
+ name = "odba_testpersistable_indexedstub_origin"
415
+ args = "xan"
416
+ ODBA.cache.should_receive(:retrieve_from_index).with(name, args)
419
417
  .times(1).and_return([result])
420
- assert_equal([result], IndexedStub.search_by_origin('xan'))
418
+ assert_equal([result], IndexedStub.search_by_origin("xan"))
421
419
 
422
420
  ## exact search by one key
423
- ODBA.cache.should_receive(:retrieve_from_index)\
424
- .with(name, args, ODBA::Persistable::Exact)\
421
+ ODBA.cache.should_receive(:retrieve_from_index)
422
+ .with(name, args, ODBA::Persistable::Exact)
425
423
  .times(1).and_return([result])
426
- assert_equal([result], IndexedStub.search_by_exact_origin('xan'))
424
+ assert_equal([result], IndexedStub.search_by_exact_origin("xan"))
427
425
 
428
426
  ## find by one key
429
- ODBA.cache.should_receive(:retrieve_from_index)\
430
- .with(name, args, ODBA::Persistable::Find)\
427
+ ODBA.cache.should_receive(:retrieve_from_index)
428
+ .with(name, args, ODBA::Persistable::Find)
431
429
  .times(1).and_return([result])
432
- assert_equal(result, IndexedStub.find_by_origin('xan'))
430
+ assert_equal(result, IndexedStub.find_by_origin("xan"))
433
431
 
434
432
  ## list available keys
435
- ODBA.cache.should_receive(:index_keys).with(name, nil)\
436
- .times(1).and_return(['key1', 'key2'])
437
- assert_equal(['key1', 'key2'], IndexedStub.origin_keys)
438
- ODBA.cache.should_receive(:index_keys).with(name, 2)\
439
- .times(1).and_return(['k1', 'k2'])
440
- assert_equal(['k1', 'k2'], IndexedStub.origin_keys(2))
433
+ ODBA.cache.should_receive(:index_keys).with(name, nil)
434
+ .times(1).and_return(["key1", "key2"])
435
+ assert_equal(["key1", "key2"], IndexedStub.origin_keys)
436
+ ODBA.cache.should_receive(:index_keys).with(name, 2)
437
+ .times(1).and_return(["k1", "k2"])
438
+ assert_equal(["k1", "k2"], IndexedStub.origin_keys(2))
441
439
  end
440
+
442
441
  def test_odba_index__redirected
443
442
  stub = IndexedStub.new
444
443
  assert_respond_to(stub, :redirect)
445
444
  assert_respond_to(stub, :redirect=)
446
445
  assert_respond_to(IndexedStub, :find_by_redirect)
447
- result = flexmock('Result')
446
+ result = flexmock("Result")
448
447
 
449
448
  ## search by one key
450
- name = 'odba_testpersistable_indexedstub_redirect'
451
- args = 'xan'
452
- ODBA.cache.should_receive(:retrieve_from_index).with(name, args)\
449
+ name = "odba_testpersistable_indexedstub_redirect"
450
+ args = "xan"
451
+ ODBA.cache.should_receive(:retrieve_from_index).with(name, args)
453
452
  .times(1).and_return([result])
454
- assert_equal([result], IndexedStub.search_by_redirect('xan'))
453
+ assert_equal([result], IndexedStub.search_by_redirect("xan"))
455
454
 
456
455
  ## exact search by one key
457
- ODBA.cache.should_receive(:retrieve_from_index)\
458
- .with(name, args, ODBA::Persistable::Exact)\
456
+ ODBA.cache.should_receive(:retrieve_from_index)
457
+ .with(name, args, ODBA::Persistable::Exact)
459
458
  .times(1).and_return([result])
460
- assert_equal([result], IndexedStub.search_by_exact_redirect('xan'))
459
+ assert_equal([result], IndexedStub.search_by_exact_redirect("xan"))
461
460
 
462
461
  ## find by one key
463
- ODBA.cache.should_receive(:retrieve_from_index)\
464
- .with(name, args, ODBA::Persistable::Find)\
462
+ ODBA.cache.should_receive(:retrieve_from_index)
463
+ .with(name, args, ODBA::Persistable::Find)
465
464
  .times(1).and_return([result])
466
- assert_equal(result, IndexedStub.find_by_redirect('xan'))
465
+ assert_equal(result, IndexedStub.find_by_redirect("xan"))
467
466
 
468
467
  ## list available keys
469
- ODBA.cache.should_receive(:index_keys).with(name, nil)\
470
- .times(1).and_return(['key1', 'key2'])
471
- assert_equal(['key1', 'key2'], IndexedStub.redirect_keys)
472
- ODBA.cache.should_receive(:index_keys).with(name, 2)\
473
- .times(1).and_return(['k1', 'k2'])
474
- assert_equal(['k1', 'k2'], IndexedStub.redirect_keys(2))
468
+ ODBA.cache.should_receive(:index_keys).with(name, nil)
469
+ .times(1).and_return(["key1", "key2"])
470
+ assert_equal(["key1", "key2"], IndexedStub.redirect_keys)
471
+ ODBA.cache.should_receive(:index_keys).with(name, 2)
472
+ .times(1).and_return(["k1", "k2"])
473
+ assert_equal(["k1", "k2"], IndexedStub.redirect_keys(2))
475
474
  end
475
+
476
476
  def test_odba_extent
477
- stub = IndexedStub.new
477
+ IndexedStub.new
478
478
  assert_respond_to(IndexedStub, :odba_extent)
479
479
  ODBA.cache.should_receive(:extent).with(IndexedStub).and_return([])
480
480
  assert_equal([], IndexedStub.odba_extent)
481
481
  end
482
+
482
483
  def test_odba_extent__with_block
483
- stub = IndexedStub.new
484
+ IndexedStub.new
484
485
  assert_respond_to(IndexedStub, :odba_extent)
485
- ODBA.cache.should_receive(:extent).with(IndexedStub).and_return(['foo'])
486
+ ODBA.cache.should_receive(:extent).with(IndexedStub).and_return(["foo"])
486
487
  IndexedStub.odba_extent { |obj|
487
- assert_equal('foo', obj)
488
+ assert_equal("foo", obj)
488
489
  }
489
490
  end
491
+
490
492
  def test_odba_replace__in_object
491
493
  ## in rollback, replace instance_variables of modified instances with
492
494
  # newly loaded unmodified ones
493
495
  modified = Object.new
494
496
  modified.extend(ODBA::Persistable)
495
- modified.instance_variable_set('@data', 'foo')
497
+ modified.instance_variable_set(:@data, "foo")
496
498
 
497
499
  reloaded = modified.dup
498
500
 
499
- modified.instance_variable_set('@data', 'bar')
500
- assert_equal('bar', modified.instance_variable_get('@data'))
501
+ modified.instance_variable_set(:@data, "bar")
502
+ assert_equal("bar", modified.instance_variable_get(:@data))
501
503
 
502
504
  modified.odba_replace!(reloaded)
503
- assert_equal('foo', modified.instance_variable_get('@data'))
505
+ assert_equal("foo", modified.instance_variable_get(:@data))
504
506
  end
507
+
505
508
  def test_odba_add_observer
506
- assert_nil(@odba.instance_variable_get('@odba_observers'))
507
- obs = flexmock('Observer')
509
+ assert_nil(@odba.instance_variable_get(:@odba_observers))
510
+ obs = flexmock("Observer")
508
511
  @odba.odba_add_observer(obs)
509
- assert_equal([obs], @odba.instance_variable_get('@odba_observers'))
512
+ assert_equal([obs], @odba.instance_variable_get(:@odba_observers))
510
513
  end
514
+
511
515
  def test_odba_delete_observer
512
- obs = flexmock('Observer')
513
- @odba.instance_variable_set('@odba_observers', [obs])
516
+ obs = flexmock("Observer")
517
+ @odba.instance_variable_set(:@odba_observers, [obs])
514
518
  @odba.odba_delete_observer(obs)
515
- assert_equal([], @odba.instance_variable_get('@odba_observers'))
519
+ assert_equal([], @odba.instance_variable_get(:@odba_observers))
516
520
  end
521
+
517
522
  def test_odba_delete_observers
518
- obs = flexmock('Observer')
519
- @odba.instance_variable_set('@odba_observers', [obs])
523
+ obs = flexmock("Observer")
524
+ @odba.instance_variable_set(:@odba_observers, [obs])
520
525
  @odba.odba_delete_observers
521
- assert_nil(@odba.instance_variable_get('@odba_observers'))
526
+ assert_nil(@odba.instance_variable_get(:@odba_observers))
522
527
  end
528
+
523
529
  def test_odba_notify_observers
524
- obs = flexmock('Observer')
530
+ obs = flexmock("Observer")
525
531
  @odba.odba_id = 218
526
- @odba.instance_variable_set('@odba_observers', [obs])
527
- obs.should_receive(:odba_update).with(:key, 'foo', 'bar')\
532
+ @odba.instance_variable_set(:@odba_observers, [obs])
533
+ obs.should_receive(:odba_update).with(:key, "foo", "bar")
528
534
  .and_return { assert(true) }
529
- @odba.odba_notify_observers(:key, 'foo', 'bar')
535
+ @odba.odba_notify_observers(:key, "foo", "bar")
530
536
  end
537
+
531
538
  def test_odba_dup
532
539
  o = Object.new
533
540
  stub = ODBA::Stub.new(15, o, nil)
534
541
  o.extend(ODBA::Persistable)
535
- o.instance_variable_set('@stub', stub)
542
+ o.instance_variable_set(:@stub, stub)
536
543
  p = o.odba_dup
537
544
  assert(p.is_a?(ODBA::Persistable))
538
- stub2 = p.instance_variable_get('@stub')
545
+ stub2 = p.instance_variable_get(:@stub)
539
546
  assert(stub2.is_a?(ODBA::Stub))
540
547
  refute_equal(stub.object_id, stub2.object_id)
541
548
  assert_equal(15, stub2.odba_id)
542
549
  end
550
+
543
551
  def test_odba_isolated_stub
544
552
  @odba.odba_id = 214
545
553
  stub = @odba.odba_isolated_stub
@@ -550,9 +558,10 @@ module ODBA
550
558
  ODBA.cache.should_receive(:fetch).with(214, nil).times(1).and_return(@odba)
551
559
  assert_equal(@odba, stub.odba_instance)
552
560
  end
561
+
553
562
  def test_odba_collection
554
563
  o = ODBAContainerInPersistable.new
555
564
  assert_equal([], o.odba_collection)
556
565
  end
557
- end
566
+ end
558
567
  end