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,45 +1,43 @@
1
1
  #!/usr/bin/env ruby
2
2
  # TestIdServer -- odba -- 10.11.2004 -- 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/id_server'
11
- require 'odba/odba'
12
- require 'odba/marshal'
3
+ require_relative "helper"
4
+ require "odba/id_server"
5
+ require "odba/odba"
6
+ require "odba/marshal"
13
7
 
14
8
  module ODBA
15
- class TestIdServer < Minitest::Test
9
+ class TestIdServer < Test::Unit::TestCase
16
10
  include FlexMock::TestCase
17
- def setup
18
- @cache = ODBA.cache = flexmock('cache')
19
- @id_server = IdServer.new
20
- @id_server.instance_variable_set('@odba_id', 1)
21
- end
11
+ def setup
12
+ @cache = ODBA.cache = flexmock("cache")
13
+ @id_server = IdServer.new
14
+ @id_server.instance_variable_set(:@odba_id, 1)
15
+ end
16
+
22
17
  def teardown
23
18
  @id_server = nil
24
19
  super
25
20
  end
26
- def test_first
21
+
22
+ def test_first
27
23
  @cache.should_receive(:store).with(@id_server).times(3)
28
- assert_equal(1, @id_server.next_id(:foo))
29
- assert_equal(1, @id_server.next_id(:bar))
30
- assert_equal(1, @id_server.next_id(:baz))
31
- end
32
- def test_consecutive
24
+ assert_equal(1, @id_server.next_id(:foo))
25
+ assert_equal(1, @id_server.next_id(:bar))
26
+ assert_equal(1, @id_server.next_id(:baz))
27
+ end
28
+
29
+ def test_consecutive
33
30
  @cache.should_receive(:store).with(@id_server).times(3)
34
- assert_equal(1, @id_server.next_id(:foo))
35
- assert_equal(2, @id_server.next_id(:foo))
36
- assert_equal(3, @id_server.next_id(:foo))
37
- end
38
- def test_dumpable
31
+ assert_equal(1, @id_server.next_id(:foo))
32
+ assert_equal(2, @id_server.next_id(:foo))
33
+ assert_equal(3, @id_server.next_id(:foo))
34
+ end
35
+
36
+ def test_dumpable
39
37
  @cache.should_receive(:store).with(@id_server).times(1)
40
- @id_server.next_id(:foo)
41
- dump = @id_server.odba_isolated_dump
42
- assert_instance_of(ODBA::IdServer, ODBA.marshaller.load(dump))
43
- end
44
- end
38
+ @id_server.next_id(:foo)
39
+ dump = @id_server.odba_isolated_dump
40
+ assert_instance_of(ODBA::IdServer, ODBA.marshaller.load(dump))
41
+ end
42
+ end
45
43
  end
data/test/test_index.rb CHANGED
@@ -1,157 +1,171 @@
1
1
  #!/usr/bin/env ruby
2
2
  # TestIndex -- oddb -- 13.05.2004 -- hwyss@ywesee.com mwalder@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/index'
11
- require 'odba/index_definition'
12
- require 'odba/odba'
3
+ require_relative "helper"
4
+ require "odba/index"
5
+ require "odba/index_definition"
6
+ require "odba/odba"
13
7
 
14
8
  module ODBA
15
9
  class Origin
16
10
  attr_accessor :term, :odba_id
17
11
  end
12
+
18
13
  class OriginSubclass < Origin
19
14
  end
15
+
20
16
  class Target
21
17
  attr_accessor :origin, :odba_id
22
18
  end
19
+
23
20
  class TargetSubclass < Target
24
21
  end
25
- class TestIndexCommon < Minitest::Test
22
+
23
+ class TestIndexCommon < Test::Unit::TestCase
26
24
  include FlexMock::TestCase
27
25
  def setup
28
- @storage = flexmock('Storage')
26
+ @storage = flexmock("Storage")
29
27
  ODBA.storage = @storage
30
28
  df = IndexDefinition.new
31
- df.index_name = 'index'
29
+ df.index_name = "index"
32
30
  df.origin_klass = :Origin
33
31
  df.target_klass = :Target
34
32
  df.resolve_origin = :origin
35
33
  df.resolve_search_term = :term
36
34
  @index = IndexCommon.new(df, ODBA)
37
35
  end
36
+
38
37
  def teardown
39
38
  @storage = nil
40
39
  ODBA.storage = nil
41
- load = File.expand_path(File.join(File.dirname(__FILE__), '../lib/odba/storage.rb'))
40
+ File.expand_path(File.join(File.dirname(__FILE__), "../lib/odba/storage.rb"))
42
41
  super
43
42
  end
43
+
44
44
  def test_delete
45
- handle = flexmock('DB-Handle')
46
- @storage.should_receive(:delete_index_element)\
47
- .with('index', 15, 'origin_id')\
48
- .times(1).and_return {assert(true) }
45
+ flexmock("DB-Handle")
46
+ @storage.should_receive(:delete_index_element)
47
+ .with("index", 15, "origin_id")
48
+ .times(1).and_return { assert(true) }
49
49
  origin = Origin.new
50
50
  origin.odba_id = 15
51
51
  @index.delete(origin)
52
- @storage.should_receive(:delete_index_element)\
53
- .with('index', 16, 'target_id')\
54
- .times(1).and_return {assert(true) }
52
+ @storage.should_receive(:delete_index_element)
53
+ .with("index", 16, "target_id")
54
+ .times(1).and_return { assert(true) }
55
55
  target = Target.new
56
56
  target.odba_id = 16
57
57
  @index.delete(target)
58
58
  end
59
+
59
60
  def test_do_update_index
60
- @storage.should_receive(:update_index)\
61
- .with('index', 12, 'foo', nil).and_return {
61
+ @storage.should_receive(:update_index)
62
+ .with("index", 12, "foo", nil).and_return {
62
63
  assert(true)
63
64
  }
64
- @index.do_update_index(12, 'foo')
65
+ @index.do_update_index(12, "foo")
65
66
  end
67
+
66
68
  def test_fill
67
69
  df = IndexDefinition.new
68
- df.index_name = 'index'
69
- df.resolve_origin = 'get_origin'
70
- df.resolve_search_term = 'the_search_term'
70
+ df.index_name = "index"
71
+ df.resolve_origin = "get_origin"
72
+ df.resolve_search_term = "the_search_term"
71
73
  index = IndexCommon.new(df, self)
72
74
 
73
- origin = flexmock('origin')
74
- origin.should_receive(:the_search_term).and_return('tst')
75
+ origin = flexmock("origin")
76
+ origin.should_receive(:the_search_term).and_return("tst")
75
77
  origin.should_receive(:odba_id).and_return(4)
76
- target = flexmock('target')
78
+ target = flexmock("target")
77
79
  target.should_receive(:get_origin).and_return(origin)
78
80
  target.should_receive(:odba_id).and_return(3)
79
81
 
80
82
  targets = [target, [target]]
81
83
 
82
- @storage.should_receive(:update_index)\
83
- .with('index', 4, 'tst', 3).times(2).and_return { assert(true) }
84
+ @storage.should_receive(:update_index)
85
+ .with("index", 4, "tst", 3).times(2).and_return { assert(true) }
84
86
 
85
87
  index.fill(targets)
86
88
  end
89
+
87
90
  def test_keys
88
- @storage.should_receive(:index_fetch_keys).with('index', nil)\
89
- .and_return { ['key1', 'key2', ''] }
90
- assert_equal(%w{key1 key2}, @index.keys)
91
- @storage.should_receive(:index_fetch_keys).with('index', 2)\
92
- .and_return { ['k1', 'k2', ''] }
93
- assert_equal(%w{k1 k2}, @index.keys(2))
94
- @storage.should_receive(:index_fetch_keys).with('index', 1)\
95
- .and_return { ['1', '2', ''] }
96
- assert_equal(%w{1 2}, @index.keys(1))
91
+ @storage.should_receive(:index_fetch_keys).with("index", nil)
92
+ .and_return { ["key1", "key2", ""] }
93
+ assert_equal(%w[key1 key2], @index.keys)
94
+ @storage.should_receive(:index_fetch_keys).with("index", 2)
95
+ .and_return { ["k1", "k2", ""] }
96
+ assert_equal(%w[k1 k2], @index.keys(2))
97
+ @storage.should_receive(:index_fetch_keys).with("index", 1)
98
+ .and_return { ["1", "2", ""] }
99
+ assert_equal(%w[1 2], @index.keys(1))
97
100
  end
101
+
98
102
  def test_origin_class
99
103
  df = IndexDefinition.new
100
- df.index_name = 'index'
104
+ df.index_name = "index"
101
105
  df.origin_klass = :Origin
102
106
  index = IndexCommon.new(df, self)
103
107
  assert_equal(true, index.origin_class?(Origin))
104
108
  assert_equal(false, index.origin_class?(Target))
105
109
  end
110
+
106
111
  def test_proc_instance_origin
107
112
  df = IndexDefinition.new
108
- df.index_name = 'index'
113
+ df.index_name = "index"
109
114
  index = IndexCommon.new(df, self)
110
115
  pr = index.proc_instance_origin
111
116
  stub = Object.new
112
117
  assert_equal([stub], pr.call(stub))
113
118
  end
119
+
114
120
  def test_proc_resolve_search_term
115
121
  df = IndexDefinition.new
116
- df.index_name = 'index'
122
+ df.index_name = "index"
117
123
  index = IndexCommon.new(df, self)
118
124
  pr = index.proc_resolve_search_term
119
125
  stub = Object.new
120
126
  assert_equal(stub.to_s.downcase, pr.call(stub))
121
127
  end
128
+
122
129
  def test_search_term
123
130
  idf = IndexDefinition.new
124
- idf.index_name = 'index'
125
- idf.resolve_search_term = 'resolve_it'
126
- origin = flexmock('origin')
127
- origin.should_receive(:resolve_it).times(1).and_return('myterm')
131
+ idf.index_name = "index"
132
+ idf.resolve_search_term = "resolve_it"
133
+ origin = flexmock("origin")
134
+ origin.should_receive(:resolve_it).times(1).and_return("myterm")
128
135
  index = IndexCommon.new(idf, ODBA)
129
- assert_equal('myterm', index.search_term(origin))
136
+ assert_equal("myterm", index.search_term(origin))
130
137
  end
138
+
131
139
  def test_set_relevance
132
- meta = flexmock('Meta')
140
+ meta = flexmock("Meta")
133
141
  meta.should_receive(:respond_to?).with(:set_relevance).and_return(true)
134
- meta.should_receive(:set_relevance).with('foo', 'bar').and_return {
135
- assert(true) }
136
- meta.should_receive(:set_relevance).with('baz', 'fro').and_return {
137
- assert(true) }
138
- @index.set_relevance(meta, [%w{foo bar}, %w{baz fro}])
142
+ meta.should_receive(:set_relevance).with("foo", "bar").and_return {
143
+ assert(true)
144
+ }
145
+ meta.should_receive(:set_relevance).with("baz", "fro").and_return {
146
+ assert(true)
147
+ }
148
+ @index.set_relevance(meta, [%w[foo bar], %w[baz fro]])
139
149
  end
150
+
140
151
  def test_update__origin
141
152
  origin = Origin.new
142
153
  origin.odba_id = 1
143
154
  origin.term = "search-term"
144
- @storage.should_receive(:index_target_ids).with('index', 1)\
145
- .and_return([[3, 'old-term'], [4, 'old-term']])
146
- @storage.should_receive(:index_delete_origin).with('index', 1, "old-term")
147
- @storage.should_receive(:update_index)\
148
- .with('index', 1, 'search-term', 3).and_return {
149
- assert(true) }
150
- @storage.should_receive(:update_index)\
151
- .with('index', 1, 'search-term', 4).and_return {
152
- assert(true) }
155
+ @storage.should_receive(:index_target_ids).with("index", 1)
156
+ .and_return([[3, "old-term"], [4, "old-term"]])
157
+ @storage.should_receive(:index_delete_origin).with("index", 1, "old-term")
158
+ @storage.should_receive(:update_index)
159
+ .with("index", 1, "search-term", 3).and_return {
160
+ assert(true)
161
+ }
162
+ @storage.should_receive(:update_index)
163
+ .with("index", 1, "search-term", 4).and_return {
164
+ assert(true)
165
+ }
153
166
  @index.update(origin)
154
167
  end
168
+
155
169
  def test_update__target
156
170
  origin = Origin.new
157
171
  origin.odba_id = 1
@@ -159,213 +173,232 @@ module ODBA
159
173
  target = Target.new
160
174
  target.odba_id = 2
161
175
  target.origin = origin
162
- @storage.should_receive(:index_origin_ids).with('index', 2)\
163
- .and_return([[1, 'old-term'], [4, 'obsolete-term']])
164
- @storage.should_receive(:index_delete_target)\
165
- .with('index', 1, 'old-term', 2).and_return { assert(true) }
166
- @storage.should_receive(:index_delete_target)\
167
- .with('index', 4, 'obsolete-term', 2).and_return { assert(true) }
168
- @storage.should_receive(:update_index)\
169
- .with('index', 1, 'search-term', 2).and_return {
170
- assert(true) }
176
+ @storage.should_receive(:index_origin_ids).with("index", 2)
177
+ .and_return([[1, "old-term"], [4, "obsolete-term"]])
178
+ @storage.should_receive(:index_delete_target)
179
+ .with("index", 1, "old-term", 2).and_return { assert(true) }
180
+ @storage.should_receive(:index_delete_target)
181
+ .with("index", 4, "obsolete-term", 2).and_return { assert(true) }
182
+ @storage.should_receive(:update_index)
183
+ .with("index", 1, "search-term", 2).and_return {
184
+ assert(true)
185
+ }
171
186
  @index.update(target)
172
187
  end
188
+
173
189
  def test_update__subclass
174
190
  origin = OriginSubclass.new
175
191
  target = TargetSubclass.new
176
- @storage.should_receive(:index_target_ids).and_return(3)
192
+ @storage.should_receive(:index_target_ids).once.and_return([3])
193
+ @storage.should_receive(:index_origin_ids).once.and_return(nil)
194
+ @storage.should_receive(:index_delete_origin).once.and_return(nil)
195
+ # @storage.should_receive(:index_origin_ids)
177
196
  @index.update(origin)
178
197
  @index.update(target)
179
198
  end
180
199
  end
181
- class TestIndex < Minitest::Test
200
+
201
+ class TestIndex < Test::Unit::TestCase
182
202
  include FlexMock::TestCase
183
203
  def setup
184
- @storage = flexmock('Storage')
185
- @storage.should_receive(:create_index).with('index')
204
+ @storage = flexmock("Storage")
205
+ @storage.should_receive(:create_index).with("index")
186
206
  ODBA.storage = @storage
187
207
  df = IndexDefinition.new
188
- df.index_name = 'index'
208
+ df.index_name = "index"
189
209
  df.origin_klass = :Origin
190
210
  df.target_klass = :Target
191
211
  df.resolve_origin = :origin
192
212
  df.resolve_search_term = :term
193
213
  @index = Index.new(df, self)
194
214
  end
215
+
195
216
  def test_fetch_ids
196
- rows = [[1,3], [2,2], [3,1]]
197
- @storage.should_receive(:retrieve_from_index)\
198
- .with('index', 'search-term', false, false).and_return rows
199
- assert_equal([1,2,3], @index.fetch_ids('search-term'))
217
+ rows = [[1, 3], [2, 2], [3, 1]]
218
+ @storage.should_receive(:retrieve_from_index)
219
+ .with("index", "search-term", false, false).and_return rows
220
+ assert_equal([1, 2, 3], @index.fetch_ids("search-term"))
200
221
  end
222
+
201
223
  def test_search_terms
202
224
  origin = Origin.new
203
- origin.term = 'resolved'
204
- assert_equal(['resolved'], @index.search_terms(origin))
205
- origin.term = ['resolved']
206
- assert_equal(['resolved'], @index.search_terms(origin))
225
+ origin.term = "resolved"
226
+ assert_equal(["resolved"], @index.search_terms(origin))
227
+ origin.term = ["resolved"]
228
+ assert_equal(["resolved"], @index.search_terms(origin))
207
229
  end
208
230
  end
209
- class TestConditionIndex < Minitest::Test
231
+
232
+ class TestConditionIndex < Test::Unit::TestCase
210
233
  include FlexMock::TestCase
211
234
  def setup
212
- @storage = flexmock('Storage')
213
- @storage.should_receive(:create_condition_index)\
214
- .with('index', {'crit1' => 'text', 'crit2' => 'Integer'})
235
+ @storage = flexmock("Storage")
236
+ @storage.should_receive(:create_condition_index)
237
+ .with("index", {"crit1" => "text", "crit2" => "Integer"})
215
238
  ODBA.storage = @storage
216
239
  df = IndexDefinition.new
217
- df.index_name = 'index'
240
+ df.index_name = "index"
218
241
  df.origin_klass = :Origin
219
242
  df.target_klass = :Target
220
243
  df.resolve_origin = :origin
221
244
  df.resolve_search_term = [
222
- ['crit1', 'term'],
223
- ['crit2', {'type' => 'Integer', 'resolve' => 'odba_id'}],
245
+ ["crit1", "term"],
246
+ ["crit2", {"type" => "Integer", "resolve" => "odba_id"}]
224
247
  ]
225
248
  @index = ConditionIndex.new(df, self)
226
249
  end
250
+
227
251
  def test_do_update_index
228
- data = {'crit1' => 'foo', 'condition' => 'like'}
229
- @storage.should_receive(:update_condition_index)\
230
- .with('index', 2, data, 3)
252
+ data = {"crit1" => "foo", "condition" => "like"}
253
+ @storage.should_receive(:update_condition_index)
254
+ .with("index", 2, data, 3)
231
255
  @index.do_update_index(2, data, 3)
232
256
  end
257
+
233
258
  def test_fetch_ids
234
- rows = [[1,3], [2,2], [3,1]]
235
- data = {'crit1' => 'foo', 'condition' => 'like'}
236
- @storage.should_receive(:retrieve_from_condition_index)\
237
- .with('index', data, false).and_return rows
238
- assert_equal([1,2,3], @index.fetch_ids(data))
259
+ rows = [[1, 3], [2, 2], [3, 1]]
260
+ data = {"crit1" => "foo", "condition" => "like"}
261
+ @storage.should_receive(:retrieve_from_condition_index)
262
+ .with("index", data, false).and_return rows
263
+ assert_equal([1, 2, 3], @index.fetch_ids(data))
239
264
  end
265
+
240
266
  def test_proc_resolve_search_term
241
267
  pr = @index.proc_resolve_search_term
242
268
  origin = Origin.new
243
- origin.term = 'search_term'
269
+ origin.term = "search_term"
244
270
  origin.odba_id = 15
245
271
  expected = {
246
- 'crit1' => 'search_term',
247
- 'crit2' => 15,
272
+ "crit1" => "search_term",
273
+ "crit2" => 15
248
274
  }
249
275
  assert_equal(expected, pr.call(origin))
250
276
  end
277
+
251
278
  def test_update_target
252
- @storage.should_receive(:condition_index_ids)\
253
- .with('index', 4, 'target_id').and_return {
279
+ @storage.should_receive(:condition_index_ids)
280
+ .with("index", 4, "target_id").and_return {
254
281
  [
255
- {'origin_id' => 1, 'crit1' => '1st',
256
- 'crit2' => 1, 'target_id' => 5},
257
- {'origin_id' => 1, 'crit1' => '1st',
258
- 'crit2' => 2, 'target_id' => 5},
282
+ {"origin_id" => 1, "crit1" => "1st",
283
+ "crit2" => 1, "target_id" => 5},
284
+ {"origin_id" => 1, "crit1" => "1st",
285
+ "crit2" => 2, "target_id" => 5}
259
286
  ]
260
287
  }
261
288
  target = Target.new
262
289
  target.odba_id = 4
263
290
  origin1 = Origin.new
264
291
  origin1.odba_id = 1
265
- origin1.term = '1st'
292
+ origin1.term = "1st"
266
293
  origin2 = Origin.new
267
- origin2.term = '2nd'
294
+ origin2.term = "2nd"
268
295
  origin2.odba_id = 2
269
296
  target.origin = [origin1, origin2]
270
- @storage.should_receive(:condition_index_delete)\
271
- .with('index', 1, [['crit1', '1st'], ['crit2', 2]], 4)\
297
+ @storage.should_receive(:condition_index_delete)
298
+ .with("index", 1, [["crit1", "1st"], ["crit2", 2]], 4)
272
299
  .and_return { assert(true) }
273
- @storage.should_receive(:update_condition_index)\
274
- .with('index', 2, [['crit1', '2nd'], ['crit2', 2]], 4)\
300
+ @storage.should_receive(:update_condition_index)
301
+ .with("index", 2, [["crit1", "2nd"], ["crit2", 2]], 4)
275
302
  .and_return { assert(true) }
276
303
  @index.update_target(target)
277
304
  end
305
+
278
306
  def test_update_origin
279
- @storage.should_receive(:condition_index_ids)\
280
- .with('index', 1, 'origin_id').and_return {
307
+ @storage.should_receive(:condition_index_ids)
308
+ .with("index", 1, "origin_id").and_return {
281
309
  [
282
- {'origin_id' => 1, 'crit1' => '1st',
283
- 'crit2' => 1, 'target_id' => 5},
284
- {'origin_id' => 1, 'crit1' => '1st',
285
- 'crit2' => 2, 'target_id' => 5},
310
+ {"origin_id" => 1, "crit1" => "1st",
311
+ "crit2" => 1, "target_id" => 5},
312
+ {"origin_id" => 1, "crit1" => "1st",
313
+ "crit2" => 2, "target_id" => 5}
286
314
  ]
287
315
  }
288
316
  target = Target.new
289
317
  target.odba_id = 4
290
318
  origin1 = Origin.new
291
319
  origin1.odba_id = 1
292
- origin1.term = '1st'
320
+ origin1.term = "1st"
293
321
  origin2 = Origin.new
294
- origin2.term = '2nd'
322
+ origin2.term = "2nd"
295
323
  origin2.odba_id = 2
296
324
  target.origin = [origin1, origin2]
297
- @storage.should_receive(:condition_index_delete)\
298
- .with('index', 1, [['crit1', '1st'], ['crit2', 2]])\
325
+ @storage.should_receive(:condition_index_delete)
326
+ .with("index", 1, [["crit1", "1st"], ["crit2", 2]])
299
327
  .and_return { assert(true) }
300
- @storage.should_receive(:update_condition_index)\
301
- .with('index', 2, [['crit1', '2nd'], ['crit2', 2]])\
328
+ @storage.should_receive(:update_condition_index)
329
+ .with("index", 2, [["crit1", "2nd"], ["crit2", 2]])
302
330
  .and_return { assert(true) }
303
331
  @index.update_origin(origin1)
304
332
  end
305
333
  end
306
- class TestFulltextIndex < Minitest::Test
334
+
335
+ class TestFulltextIndex < Test::Unit::TestCase
307
336
  include FlexMock::TestCase
308
337
  def setup
309
- @storage = flexmock('Storage')
310
- @storage.should_receive(:create_fulltext_index).with('index')
338
+ @storage = flexmock("Storage")
339
+ @storage.should_receive(:create_fulltext_index).with("index")
311
340
  ODBA.storage = @storage
312
341
  df = IndexDefinition.new
313
- df.index_name = 'index'
342
+ df.index_name = "index"
314
343
  df.origin_klass = :Origin
315
344
  df.target_klass = :Target
316
345
  df.resolve_origin = :origin
317
- df.resolve_search_term = 'term'
346
+ df.resolve_search_term = "term"
318
347
  @index = FulltextIndex.new(df, self)
319
348
  end
349
+
320
350
  def test_fetch_ids
321
- rows = [[1,3], [2,2], [3,1]]
322
- @storage.should_receive(:retrieve_from_fulltext_index)\
323
- .with('index', 'search-term', false).and_return rows
324
- assert_equal([1,2,3], @index.fetch_ids('search-term'))
351
+ rows = [[1, 3], [2, 2], [3, 1]]
352
+ @storage.should_receive(:retrieve_from_fulltext_index)
353
+ .with("index", "search-term", false).and_return rows
354
+ assert_equal([1, 2, 3], @index.fetch_ids("search-term"))
325
355
  end
356
+
326
357
  def test_do_update_index
327
- @storage.should_receive(:update_fulltext_index)\
328
- .with('index', 3, 'some full text', 4)
329
- @index.do_update_index(3, 'some full text', 4)
358
+ @storage.should_receive(:update_fulltext_index)
359
+ .with("index", 3, "some full text", 4)
360
+ @index.do_update_index(3, "some full text", 4)
330
361
  end
362
+
331
363
  def test_update_target
332
364
  ## only deletes entries for the current target, and inserts from
333
365
  # all origins
334
- @storage.should_receive(:fulltext_index_delete)\
335
- .with('index', 4, 'target_id')
336
- @storage.should_receive(:update_fulltext_index)\
337
- .with('index', 1, 'fulltext term', 4)
338
- @storage.should_receive(:update_fulltext_index)\
339
- .with('index', 2, 'fulltext term', 4)
366
+ @storage.should_receive(:fulltext_index_delete)
367
+ .with("index", 4, "target_id")
368
+ @storage.should_receive(:update_fulltext_index)
369
+ .with("index", 1, "fulltext term", 4)
370
+ @storage.should_receive(:update_fulltext_index)
371
+ .with("index", 2, "fulltext term", 4)
340
372
  target = Target.new
341
373
  target.odba_id = 4
342
374
  origin1 = Origin.new
343
375
  origin1.odba_id = 1
344
- origin1.term = ['fulltext term']
376
+ origin1.term = ["fulltext term"]
345
377
  origin2 = Origin.new
346
- origin2.term = ['fulltext term']
378
+ origin2.term = ["fulltext term"]
347
379
  origin2.odba_id = 2
348
380
  target.origin = [origin1, origin2]
349
381
  @index.update(target)
350
382
  end
383
+
351
384
  def test_update_origin
352
385
  ## deletes all entries for the current origin and must restore
353
386
  # entries for all targets!
354
- @storage.should_receive(:fulltext_index_target_ids)\
355
- .times(1).with('index', 1).and_return([[4],[5]])
356
- @storage.should_receive(:fulltext_index_delete)\
357
- .times(1).with('index', 1, 'origin_id')
358
- @storage.should_receive(:update_fulltext_index)\
359
- .times(1).with('index', 1, 'fulltext term', 4)
360
- @storage.should_receive(:update_fulltext_index)\
361
- .times(1).with('index', 1, 'fulltext term', 5)
387
+ @storage.should_receive(:fulltext_index_target_ids)
388
+ .times(1).with("index", 1).and_return([[4], [5]])
389
+ @storage.should_receive(:fulltext_index_delete)
390
+ .times(1).with("index", 1, "origin_id")
391
+ @storage.should_receive(:update_fulltext_index)
392
+ .times(1).with("index", 1, "fulltext term", 4)
393
+ @storage.should_receive(:update_fulltext_index)
394
+ .times(1).with("index", 1, "fulltext term", 5)
362
395
  target = Target.new
363
396
  target.odba_id = 4
364
397
  origin1 = Origin.new
365
398
  origin1.odba_id = 1
366
- origin1.term = ['fulltext term']
399
+ origin1.term = ["fulltext term"]
367
400
  origin2 = Origin.new
368
- origin2.term = ['fulltext term']
401
+ origin2.term = ["fulltext term"]
369
402
  origin2.odba_id = 2
370
403
  target.origin = [origin1, origin2]
371
404
  @index.update(origin1)