odba 1.1.2 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,7 @@ module ODBA
10
10
  def initialize(odba_id, odba_container, receiver)
11
11
  @odba_id = odba_id
12
12
  @odba_container = odba_container
13
- @odba_class = receiver.class unless receiver.nil?
13
+ @odba_class = receiver.class unless receiver.nil?
14
14
  @receiver_loaded = true
15
15
  end
16
16
  def class
@@ -50,16 +50,19 @@ module ODBA
50
50
  @receiver_loaded = true
51
51
  if(@odba_container)
52
52
  @odba_container.odba_replace_stubs(@odba_id, @receiver)
53
- else
53
+ else
54
54
  warn "Potential Memory-Leak: stub for #{@receiver.class}##{@odba_id} was saved without container"
55
55
  end
56
56
  @receiver
57
57
  rescue OdbaError => e
58
- warn "ODBA::Stub was unable to replace #{@odba_class}##{@odba_id} from #{@odba_container.class}:##{@odba_container.odba_id}"
58
+ puts "OdbaError"
59
+ puts caller[0..10].join("\n")
60
+ warn "ODBA::Stub was unable to replace #{@odba_class}##{@odba_id} from #{@odba_container.class}:##{@odba_container.odba_id}. raise OdbaError"
61
+ raise OdbaError
59
62
  end
60
63
  end
61
64
  alias :odba_instance :odba_receiver
62
- # A stub always references a Persistable that has
65
+ # A stub always references a Persistable that has
63
66
  # already been saved.
64
67
  def odba_unsaved?(snapshot_level=nil)
65
68
  false
@@ -78,8 +81,8 @@ module ODBA
78
81
  end
79
82
  end
80
83
  no_override = [
81
- "class", "is_a?", "__id__", "__send__", "inspect",
82
- "eql?", "nil?", "respond_to?", "object_id",
84
+ "class", "is_a?", "__id__", "__send__", "inspect",
85
+ "eql?", "nil?", "respond_to?", "object_id",
83
86
  "instance_variables", "instance_variable_get",
84
87
  "instance_variable_set", "==",
85
88
  ## methods defined in persistable.rb:Object
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  class Odba
4
- VERSION = '1.1.2'
4
+ VERSION = '1.1.7'
5
5
  end
@@ -1,7 +1,5 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'odba/version'
2
+ require_relative 'lib/odba/version'
5
3
 
6
4
  Gem::Specification.new do |spec|
7
5
  spec.name = "odba"
@@ -16,13 +14,14 @@ Gem::Specification.new do |spec|
16
14
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
15
  spec.require_paths = ["lib"]
18
16
 
19
- spec.add_dependency 'ydbi', '>=0.5.1'
20
- spec.add_dependency 'ydbd-pg','>=0.5.1'
21
-
17
+ spec.add_dependency 'ydbi', '>=0.5.7'
18
+ spec.add_dependency 'ydbd-pg','>=0.5.7'
19
+
22
20
  spec.add_development_dependency "bundler"
23
21
  spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
24
23
  spec.add_development_dependency "flexmock"
25
- spec.add_development_dependency "simplecov"
26
- spec.add_development_dependency "minitest" if /^1\./.match(RUBY_VERSION)
24
+ spec.add_development_dependency "minitest"
25
+ spec.add_development_dependency "test-unit"
26
+ spec.add_development_dependency "debug_inspector"
27
27
  end
28
-
@@ -5,6 +5,7 @@ $: << File.dirname(__FILE__)
5
5
  $: << File.expand_path('../lib', File.dirname(__FILE__))
6
6
 
7
7
  require 'minitest/autorun'
8
+ require 'flexmock/test_unit'
8
9
  require 'flexmock'
9
10
  require 'odba/persistable'
10
11
  require 'odba/stub'
@@ -6,6 +6,7 @@ $: << File.dirname(__FILE__)
6
6
  $: << File.expand_path('../lib/', File.dirname(__FILE__))
7
7
 
8
8
  require 'minitest/autorun'
9
+ require 'flexmock/test_unit'
9
10
  require 'flexmock'
10
11
  require 'odba/cache'
11
12
  require 'odba/cache_entry'
@@ -16,7 +17,7 @@ require 'odba/odba_error'
16
17
  require 'odba/odba'
17
18
 
18
19
  module ODBA
19
- class Cache
20
+ class Cache
20
21
  CLEANING_INTERVAL = 0
21
22
  MAIL_RECIPIENTS = []
22
23
  MAIL_FROM = "test@testfirst.local"
@@ -216,7 +217,7 @@ module ODBA
216
217
  @marshal.should_receive(:load).and_return {|dump|
217
218
  receiver
218
219
  }
219
- @storage.should_receive(:restore_collection).and_return {|*args|
220
+ @storage.should_receive(:restore_collection).and_return {|*args|
220
221
  []
221
222
  }
222
223
  receiver.instance_variable_set("@odba_id", 23)
@@ -233,7 +234,7 @@ module ODBA
233
234
  def test_fetch_error
234
235
  receiver = flexmock
235
236
  @storage.should_receive(:restore).and_return { |odba_id|
236
- nil
237
+ nil
237
238
  }
238
239
  assert_raises(OdbaError) {
239
240
  @cache.load_object(23, receiver)
@@ -289,17 +290,17 @@ module ODBA
289
290
  assert_equal(new_collection, col)
290
291
  }
291
292
 
292
- @storage.should_receive(:restore_collection).and_return {
293
+ @storage.should_receive(:restore_collection).and_return {
293
294
  old_collection.collect { |key, val|
294
- [Marshal.dump(key.odba_isolated_stub),
295
+ [Marshal.dump(key.odba_isolated_stub),
295
296
  Marshal.dump(val.odba_isolated_stub)]
296
297
  }
297
298
  }
298
- @storage.should_receive(:collection_remove).and_return { |odba_id, key|
299
+ @storage.should_receive(:collection_remove).and_return { |odba_id, key|
299
300
  assert_equal(54, odba_id)
300
301
  assert_equal(Marshal.dump('key1'.odba_isolated_stub), key)
301
302
  }
302
- @storage.should_receive(:collection_store).and_return { |odba_id, key, value|
303
+ @storage.should_receive(:collection_store).and_return { |odba_id, key, value|
303
304
  assert_equal(54, odba_id)
304
305
  assert_equal(Marshal.dump('key3'.odba_isolated_stub), key)
305
306
  assert_equal(Marshal.dump('val3'.odba_isolated_stub), value)
@@ -308,7 +309,7 @@ module ODBA
308
309
  @cache.fetched = {
309
310
  54 => cache_entry
310
311
  }
311
-
312
+
312
313
  obj = flexmock('Obj')
313
314
  obj.should_receive(:odba_id).and_return { 54 }
314
315
  obj.should_receive(:odba_collection).and_return { new_collection }
@@ -349,10 +350,10 @@ module ODBA
349
350
  end
350
351
  def test_fill_index
351
352
  foo = flexmock("foo")
352
- foo.should_receive(:fill).and_return { |target|
353
+ foo.should_receive(:fill).and_return { |target|
353
354
  assert_equal("baz", target)
354
355
  }
355
- @cache.indices = {
356
+ @cache.indices = {
356
357
  "foo" => foo
357
358
  }
358
359
  @cache.fill_index("foo", "baz")
@@ -436,9 +437,9 @@ module ODBA
436
437
 
437
438
  @storage.should_receive(:restore_collection).and_return { [] }
438
439
  if(block)
439
- @storage.should_receive(:store, &block).and_return
440
+ @storage.should_receive(:store, &block).and_return
440
441
  else
441
- @storage.should_receive(:store).and_return {
442
+ @storage.should_receive(:store).and_return {
442
443
  assert(true)
443
444
  }
444
445
  end
@@ -453,39 +454,39 @@ module ODBA
453
454
  origin_obj.odba_connection = delete_item
454
455
  @cache.fetched.store(1, delete_item)
455
456
  @storage.should_receive(:retrieve_connected_objects).and_return { |id|
456
- [[2]]
457
+ [[2]]
457
458
  }
458
459
  prepare_fetch(2, origin_obj)
459
- @storage.should_receive(:restore_collection).and_return { |*args|
460
+ @storage.should_receive(:restore_collection).and_return { |*args|
460
461
  []
461
462
  }
462
463
  @storage.should_receive(:store).and_return { |id, dump, name, prefetch, klass| }
463
- @storage.should_receive(:ensure_object_connections).and_return { }
464
- @storage.should_receive(:delete_persistable).and_return { |id| }
464
+ @storage.should_receive(:ensure_object_connections).and_return { }
465
+ @storage.should_receive(:delete_persistable).and_return { |id| }
465
466
  @marshal.should_receive(:dump).and_return { |ob| "foo"}
466
467
  @cache.delete(delete_item)
467
468
  assert_equal(1, @cache.fetched.size)
468
- assert_equal(nil, origin_obj.odba_connection)
469
+ assert_nil(origin_obj.odba_connection)
469
470
  end
470
471
  def prepare_delete(mock, name, id)
471
472
  mock.should_receive(:odba_id).and_return { id }
472
473
  mock.should_receive(:odba_name).and_return { name }
473
474
  mock.should_receive(:odba_notify_observers).and_return { |key, id1, id2|
474
- assert_equal(:delete, key)
475
+ assert_equal(:delete, key)
475
476
  }
476
477
  @storage.should_receive(:retrieve_connected_objects).and_return { |id|
477
478
  []
478
479
  }
479
480
  mock.should_receive(:origin_class?).and_return { true }
480
481
  mock.should_receive(:odba_id).and_return { id }
481
- @storage.should_receive(:delete_persistable).and_return { |id_arg|
482
+ @storage.should_receive(:delete_persistable).and_return { |id_arg|
482
483
  assert_equal(id, id_arg)
483
484
  }
484
485
  @storage.should_receive(:delete_index_element).and_return { }
485
486
  end
486
487
  def prepare_bulk_restore(rows)
487
488
  rows.each { |odba_mock|
488
- ## according to recent changes, objects are extended with
489
+ ## according to recent changes, objects are extended with
489
490
  # ODBA::Persistable after loading - this enables ad-hoc storing
490
491
  # but messes up loads of tests
491
492
  @marshal.should_receive(:load).and_return { |dump|
@@ -591,7 +592,7 @@ module ODBA
591
592
  ## store o1
592
593
  @marshal.should_receive(:dump).times(3).and_return { |obj|
593
594
  "dump%i" % obj.odba_id
594
- }
595
+ }
595
596
  next_id = 1
596
597
  @storage.should_receive(:next_id).and_return { next_id += 1 }
597
598
  @storage.should_receive(:store).with(1,'dump1',nil,nil,Object)\
@@ -631,7 +632,7 @@ module ODBA
631
632
  .times(1).and_return(o4)
632
633
  @cache.fetched.store(1, ODBA::CacheEntry.new(o1))
633
634
  assert_raises(RuntimeError) {
634
- ODBA.transaction {
635
+ ODBA.transaction {
635
636
  o2.instance_variable_set('@other', o3)
636
637
  o1.instance_variable_set('@other', o2)
637
638
  o1.odba_store
@@ -5,6 +5,7 @@ $: << File.dirname(__FILE__)
5
5
  $: << File.expand_path("../lib", File.dirname(__FILE__))
6
6
 
7
7
  require 'minitest/autorun'
8
+ require 'flexmock/test_unit'
8
9
  require 'flexmock'
9
10
  require 'odba/cache_entry'
10
11
  require 'odba/odba'
@@ -4,6 +4,7 @@
4
4
  $: << File.expand_path('../lib', File.dirname(__FILE__))
5
5
 
6
6
  require 'minitest/autorun'
7
+ require 'flexmock/test_unit'
7
8
  require 'flexmock'
8
9
  require 'odba/connection_pool'
9
10
  ## connection_pool requires 'dbi', which unshifts the site_ruby dir
@@ -4,8 +4,9 @@
4
4
  $: << File.expand_path('../lib', File.dirname(__FILE__))
5
5
 
6
6
  require 'minitest/autorun'
7
- require 'odba/drbwrapper'
7
+ require 'flexmock/test_unit'
8
8
  require 'flexmock'
9
+ require 'odba/drbwrapper'
9
10
 
10
11
  module ODBA
11
12
  class TestDRbWrapper < Minitest::Test
@@ -4,11 +4,12 @@
4
4
  $: << File.dirname(__FILE__)
5
5
  $: << File.expand_path('../lib/', File.dirname(__FILE__))
6
6
 
7
+ require 'minitest/autorun'
8
+ require 'flexmock/test_unit'
9
+ require 'flexmock'
7
10
  require 'odba/persistable'
8
11
  require 'odba/stub'
9
12
  require 'odba/odba'
10
- require 'minitest/autorun'
11
- require 'flexmock'
12
13
 
13
14
  module ODBA
14
15
  class TestHash < Minitest::Test
@@ -5,6 +5,7 @@ $: << File.dirname(__FILE__)
5
5
  $: << File.expand_path('../lib', File.dirname(__FILE__))
6
6
 
7
7
  require 'minitest/autorun'
8
+ require 'flexmock/test_unit'
8
9
  require 'flexmock'
9
10
  require 'odba/id_server'
10
11
  require 'odba/odba'
@@ -5,10 +5,11 @@ $: << File.dirname(__FILE__)
5
5
  $: << File.expand_path("../lib", File.dirname(__FILE__))
6
6
 
7
7
  require 'minitest/autorun'
8
+ require 'flexmock/test_unit'
9
+ require 'flexmock'
8
10
  require 'odba/index'
9
11
  require 'odba/index_definition'
10
12
  require 'odba/odba'
11
- require 'flexmock'
12
13
 
13
14
  module ODBA
14
15
  class Origin
@@ -310,7 +311,6 @@ module ODBA
310
311
  ODBA.storage = @storage
311
312
  df = IndexDefinition.new
312
313
  df.index_name = 'index'
313
- df.dictionary = 'german'
314
314
  df.origin_klass = :Origin
315
315
  df.target_klass = :Target
316
316
  df.resolve_origin = :origin
@@ -320,12 +320,12 @@ module ODBA
320
320
  def test_fetch_ids
321
321
  rows = [[1,3], [2,2], [3,1]]
322
322
  @storage.should_receive(:retrieve_from_fulltext_index)\
323
- .with('index', 'search-term', 'german', false).and_return rows
323
+ .with('index', 'search-term', false).and_return rows
324
324
  assert_equal([1,2,3], @index.fetch_ids('search-term'))
325
325
  end
326
326
  def test_do_update_index
327
327
  @storage.should_receive(:update_fulltext_index)\
328
- .with('index', 3, 'some full text', 4, 'german')
328
+ .with('index', 3, 'some full text', 4)
329
329
  @index.do_update_index(3, 'some full text', 4)
330
330
  end
331
331
  def test_update_target
@@ -334,9 +334,9 @@ module ODBA
334
334
  @storage.should_receive(:fulltext_index_delete)\
335
335
  .with('index', 4, 'target_id')
336
336
  @storage.should_receive(:update_fulltext_index)\
337
- .with('index', 1, 'fulltext term', 4, 'german')
337
+ .with('index', 1, 'fulltext term', 4)
338
338
  @storage.should_receive(:update_fulltext_index)\
339
- .with('index', 2, 'fulltext term', 4, 'german')
339
+ .with('index', 2, 'fulltext term', 4)
340
340
  target = Target.new
341
341
  target.odba_id = 4
342
342
  origin1 = Origin.new
@@ -356,9 +356,9 @@ module ODBA
356
356
  @storage.should_receive(:fulltext_index_delete)\
357
357
  .times(1).with('index', 1, 'origin_id')
358
358
  @storage.should_receive(:update_fulltext_index)\
359
- .times(1).with('index', 1, 'fulltext term', 4, 'german')
359
+ .times(1).with('index', 1, 'fulltext term', 4)
360
360
  @storage.should_receive(:update_fulltext_index)\
361
- .times(1).with('index', 1, 'fulltext term', 5, 'german')
361
+ .times(1).with('index', 1, 'fulltext term', 5)
362
362
  target = Target.new
363
363
  target.odba_id = 4
364
364
  origin1 = Origin.new
@@ -3,6 +3,8 @@
3
3
  $: << File.expand_path('../lib', File.dirname(__FILE__))
4
4
 
5
5
  require 'minitest/autorun'
6
+ require 'flexmock/test_unit'
7
+ require 'flexmock'
6
8
  require 'odba/marshal'
7
9
 
8
10
  module ODBA
@@ -4,14 +4,15 @@
4
4
  $: << File.dirname(__FILE__)
5
5
  $: << File.expand_path('../lib/', File.dirname(__FILE__))
6
6
 
7
+ require 'minitest/autorun'
8
+ require 'flexmock/test_unit'
9
+ require 'flexmock'
7
10
  require 'odba/persistable'
8
11
  require 'odba/stub'
9
12
  require 'odba/cache'
10
13
  require 'odba/odba'
11
14
  require 'odba/storage'
12
15
  require 'odba/marshal'
13
- require 'minitest/autorun'
14
- require 'flexmock'
15
16
  require 'yaml'
16
17
 
17
18
  module ODBA
@@ -30,7 +31,7 @@ module ODBA
30
31
  class ODBAContainerInPersistable
31
32
  include ODBA::Persistable
32
33
  ODBA_SERIALIZABLE = ['@serializable']
33
- attr_accessor :non_replaceable, :replaceable, :replaceable2,
34
+ attr_accessor :non_replaceable, :replaceable, :replaceable2,
34
35
  :array, :odba_persistent, :serializable
35
36
  attr_accessor :odba_snapshot_level
36
37
  end
@@ -181,11 +182,11 @@ module ODBA
181
182
  level1.replaceable = level2
182
183
 
183
184
  saved.odba_persistent = true
184
- ODBA.cache.should_receive(:store).times(3).and_return {
185
+ ODBA.cache.should_receive(:store).times(3).and_return {
185
186
  assert(true)
186
187
  2
187
188
  }
188
-
189
+
189
190
  @odba.odba_store_unsaved
190
191
  end
191
192
  def test_odba_store_unsaved_hash
@@ -196,12 +197,12 @@ module ODBA
196
197
  level1.replaceable = hash
197
198
  level1.non_replaceable = non_rep_hash
198
199
  non_rep_hash.odba_persistent = true
199
-
200
- ODBA.cache.should_receive(:store).times(2).and_return {
200
+
201
+ ODBA.cache.should_receive(:store).times(2).and_return {
201
202
  assert(true)
202
203
  2
203
204
  }
204
-
205
+
205
206
  level1.odba_store_unsaved
206
207
  end
207
208
  def test_dup
@@ -225,8 +226,8 @@ module ODBA
225
226
  odba_twin = @odba.odba_dup
226
227
  odba_twin.replaceable.flexmock_verify
227
228
  odba_twin.replaceable2.flexmock_verify
228
- assert_equal(odba_twin, stub_container)
229
- assert_equal(odba_twin, stub_container2)
229
+ assert_equal(odba_twin, stub_container)
230
+ assert_equal(odba_twin, stub_container2)
230
231
  end
231
232
  def test_odba_unsaved_true
232
233
  @odba.instance_variable_set("@odba_persistent", false)
@@ -282,7 +283,7 @@ module ODBA
282
283
  ODBA.cache.should_receive(:next_id).and_return(1)
283
284
  dump, hash = odba.odba_isolated_dump
284
285
  obj = ODBA.marshaller.load(dump)
285
- assert_equal(nil, obj.excluded)
286
+ assert_nil(obj.excluded)
286
287
  assert_equal("baz", obj.included)
287
288
  ODBA.marshaller = tmp
288
289
  end
@@ -385,7 +386,7 @@ module ODBA
385
386
  }
386
387
  ODBA.cache.should_receive(:retrieve_from_index).with(name, args)\
387
388
  .times(1).and_return([result])
388
- assert_equal([result],
389
+ assert_equal([result],
389
390
  IndexedStub.search_by_foo_and_bar('oof', 'rab'))
390
391
 
391
392
  ## exact search by multiple keys
@@ -393,11 +394,11 @@ module ODBA
393
394
  ODBA.cache.should_receive(:retrieve_from_index)\
394
395
  .with(name, args, Persistable::Exact)\
395
396
  .times(1).and_return([result])
396
- assert_equal([result],
397
+ assert_equal([result],
397
398
  IndexedStub.search_by_exact_foo_and_bar('oof', 'rab'))
398
399
 
399
400
  ## find by multiple keys
400
- args = {:foo => {'value' => 7,'condition' => '='},
401
+ args = {:foo => {'value' => 7,'condition' => '='},
401
402
  :bar => {'value' => 'rab','condition' => 'like'}}
402
403
  ODBA.cache.should_receive(:retrieve_from_index)\
403
404
  .with(name, args, Persistable::Find)\
@@ -497,7 +498,7 @@ module ODBA
497
498
 
498
499
  modified.instance_variable_set('@data', 'bar')
499
500
  assert_equal('bar', modified.instance_variable_get('@data'))
500
-
501
+
501
502
  modified.odba_replace!(reloaded)
502
503
  assert_equal('foo', modified.instance_variable_get('@data'))
503
504
  end
@@ -553,5 +554,5 @@ module ODBA
553
554
  o = ODBAContainerInPersistable.new
554
555
  assert_equal([], o.odba_collection)
555
556
  end
556
- end
557
+ end
557
558
  end