Class: ODDB::TestSequence

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
FlexMock::TestCase
Defined in:
test/test_model/sequence.rb

Defined Under Namespace

Classes: StubActiveAgent, StubPatinfo

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



93
94
95
96
# File 'test/test_model/sequence.rb', line 93

def setup
  @seq = ODDB::Sequence.new(1)
  @seq.pointer = ODDB::Persistence::Pointer.new([:sequence, 1])
end

- (Object) test_active



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'test/test_model/sequence.rb', line 97

def test_active
  assert_nil @seq.active?
  @seq.registration = flexmock :active? => false
  assert_equal false, @seq.active?
  @seq.registration = flexmock :active? => true
  assert_equal true, @seq.active?
  @seq.inactive_date = @@two_years_ago
  assert_equal false, @seq.active?
  @seq.inactive_date = @@two_years_ago + 1
  assert_equal true, @seq.active?
  @seq.registration = flexmock :active? => true, :company => 'company',
                               :may_violate_patent? => true
  seq = flexmock :patent_protected? => true, :company => 'other',
                 :active_agents => []
  @seq.atc_class = flexmock :sequences => [seq]
  assert_equal false, @seq.active?
end

- (Object) test_active_agents



139
140
141
142
143
144
# File 'test/test_model/sequence.rb', line 139

def test_active_agents
  assert_equal [], @seq.active_agents
  @seq.compositions.push flexmock(:active_agents => ['act1', 'act2']),
                         flexmock(:active_agents => ['act3'])
  assert_equal ['act1', 'act2', 'act3'], @seq.active_agents
end

- (Object) test_active_package_count



122
123
124
125
126
127
128
129
# File 'test/test_model/sequence.rb', line 122

def test_active_package_count
  pac1 = flexmock :active? => true
  pac2 = flexmock :active? => false
  @seq.packages.update '001' => pac1, '002' => pac2
  assert_equal 0, @seq.active_package_count
  @seq.registration = flexmock :active? => true
  assert_equal 1, @seq.active_package_count
end

- (Object) test_active_packages



114
115
116
117
118
119
120
121
# File 'test/test_model/sequence.rb', line 114

def test_active_packages
  pac1 = flexmock :active? => true
  pac2 = flexmock :active? => false
  @seq.packages.update '001' => pac1, '002' => pac2
  assert_equal [], @seq.active_packages
  @seq.registration = flexmock :active? => true
  assert_equal [pac1], @seq.active_packages
end

- (Object) test_active_patinfo



130
131
132
133
134
135
136
137
138
# File 'test/test_model/sequence.rb', line 130

def test_active_patinfo
  assert_nil @seq.active_patinfo
  @seq.pdf_patinfo = 'path-to.pdf'
  assert_nil @seq.active_patinfo
  @seq.registration = flexmock :active? => true
  assert_equal 'path-to.pdf', @seq.active_patinfo
  @seq.deactivate_patinfo = @@today
  assert_equal false, @seq.active_patinfo
end

- (Object) test_adjust_types



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'test/test_model/sequence.rb', line 145

def test_adjust_types
  values = {
    :galenic_form =>  Persistence::Pointer.new([:galenic_form, 'Tabletten']),
    :name         =>  "Aspirin Cardio",
    :dose         =>  [100, 'mg'],
    :atc_class    =>  'N02BA01',
  }
  app = StubSequenceApp.new
  expected = {
    :galenic_form =>  app.galenic_form('Tabletten'),
    :name         =>  "Aspirin Cardio",
    :dose         =>  ODDB::Dose.new(100, 'mg'),
    :atc_class    =>  app.atc_class('N02BA01'),
  }
  assert_equal(expected, @seq.adjust_types(values, app))
end

- (Object) test_adjust_types__2



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'test/test_model/sequence.rb', line 161

def test_adjust_types__2
  values = {
    :galenic_form =>  Persistence::Pointer.new([:galenic_form, 'Tabletten']),
    :name         =>  "Aspirin Cardio",
    :dose         =>  ODDB::Dose.new(100, 'mg'),
    :atc_class    =>  'N02BA01',
    :inactive_date=> '10.11.2010',
  }
  app = StubSequenceApp.new
  expected = {
    :galenic_form =>  app.galenic_form('Tabletten'),
    :name         =>  "Aspirin Cardio",
    :dose         =>  ODDB::Dose.new(100, 'mg'),
    :atc_class    =>  app.atc_class('N02BA01'),
    :inactive_date=> Date.new(2010,11,10),
  }
  assert_equal(expected, @seq.adjust_types(values, app))
end

- (Object) test_atc_class_writer



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'test/test_model/sequence.rb', line 179

def test_atc_class_writer
  assert_nothing_raised { @seq.atc_class = nil }
  atc1 = StubSequenceAtcClass.new
  atc2 = StubSequenceAtcClass.new
  assert_nil(atc1.state)
  assert_nil(atc2.state)
  @seq.atc_class = atc1
  assert_equal(:added, atc1.state)
  assert_nil(atc2.state)
  assert_nothing_raised { @seq.atc_class = nil }
  assert_equal(:added, atc1.state)
  assert_nil(atc2.state)
  assert_equal(atc1, @seq.atc_class)
  @seq.atc_class = atc2
  assert_equal(:removed, atc1.state)
  assert_equal(:added, atc2.state)
end

- (Object) test_basename



196
197
198
199
200
201
202
203
204
205
# File 'test/test_model/sequence.rb', line 196

def test_basename
  assert_nil @seq.basename
  @seq.name_base = 'Some Product'
  assert_equal 'Some Product', @seq.basename
  @seq.name_base = 'Some Product 50 mg'
  ## should possibly be stripped?
  assert_equal 'Some Product ', @seq.basename
  @seq.name_base = '4N Product 50 mg'
  assert_equal '4N Product ', @seq.basename
end

- (Object) test_checkout



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'test/test_model/sequence.rb', line 206

def test_checkout
  atc = flexmock 'atc'
  atc.should_receive(:respond_to?).with(:remove_sequence).and_return true
  atc.should_receive(:remove_sequence).with(@seq).times(1).and_return do
    assert true
  end
  @seq.instance_variable_set '@atc_class', atc
  patinfo = flexmock 'patinfo'
  patinfo.should_receive(:respond_to?).with(:remove_sequence).and_return true
  patinfo.should_receive(:remove_sequence).with(@seq).times(1).and_return do
    assert true
  end
  @seq.instance_variable_set '@patinfo', patinfo
  pac = flexmock 'package'
  pac.should_receive(:checkout).times(1).and_return do
    assert true
  end
  pac.should_receive(:odba_delete).times(1).and_return do
    assert true
  end
  @seq.packages.store '001', pac
  comp = flexmock 'composition'
  comp.should_receive(:checkout).times(1).and_return do
    assert true
  end
  comp.should_receive(:odba_delete).times(1).and_return do
    assert true
  end
  @seq.compositions.push comp
  @seq.checkout
end

- (Object) test_comparable



319
320
321
322
323
# File 'test/test_model/sequence.rb', line 319

def test_comparable
  assert_equal false, @seq.comparable?(@seq)
  seq = flexmock :compositions => [], :active? => true
  assert_equal true, @seq.comparable?(seq)
end

- (Object) test_comparables



237
238
239
240
241
242
243
244
# File 'test/test_model/sequence.rb', line 237

def test_comparables
  assert_equal [], @seq.comparables
  seq1 = flexmock 'seq1', :compositions => [], :active? => true
  seq2 = flexmock 'seq2', :compositions => ['different'], :active? => true
  atc = flexmock :sequences => [seq1, seq2]
  @seq.instance_variable_set('@atc_class', atc)
  assert_equal [seq1], @seq.comparables
end

- (Object) test_comparables1



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'test/test_model/sequence.rb', line 245

def test_comparables1
  reg = FlexMock.new
  reg.should_receive(:active?).and_return { true }
  reg.should_receive(:may_violate_patent?).and_return { false }
  @seq.registration = reg
  atc = StubSequenceAtcClass.new
  @seq.atc_class = atc
  comp = ODDB::Composition.new
  subst = ODDB::Substance.new
  subst.descriptions.store 'lt', 'LEVOMENTHOLUM'
  active_agent = ODDB::ActiveAgent.new('LEVOMENTHOLUM')
  active_agent.substance = subst
  active_agent.composition = comp
  @seq.compositions.push comp
  comp.galenic_form = StubSequenceGalenicForm.new
  comparable = ODDB::Sequence.new('02')
  comparable.registration = reg
  comparable.atc_class = atc
  comparable.compositions.push comp
  assert_equal([comparable], @seq.comparables)
end

- (Object) test_comparables2



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'test/test_model/sequence.rb', line 266

def test_comparables2
  reg = FlexMock.new
  reg.should_receive(:active?).and_return { true }
  reg.should_receive(:may_violate_patent?).and_return { false }
  @seq.registration = reg
  atc = StubSequenceAtcClass.new
  @seq.atc_class = atc
  comp = ODDB::Composition.new
  subst = ODDB::Substance.new
  subst.descriptions.store 'lt', 'LEVOMENTHOLUM'
  active_agent = ODDB::ActiveAgent.new('LEVOMENTHOLUM')
  active_agent.substance = subst
  active_agent.composition = comp
  @seq.compositions.push comp
  comp.galenic_form = StubSequenceGalenicForm.new
  comparable = ODDB::Sequence.new('02')
  comparable.registration = reg
  comparable.atc_class = atc
  comp = ODDB::Composition.new
  subst = ODDB::Substance.new
  subst.descriptions.store 'lt', 'ACIDUM ACETYLSALICYLICUM'
  active_agent = ODDB::ActiveAgent.new('ACIDUM ACETYLSALICYLICUM')
  active_agent.substance = subst
  active_agent.composition = comp
  comparable.compositions.push comp
  assert_equal([], @seq.comparables)
end

- (Object) test_comparables3



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'test/test_model/sequence.rb', line 293

def test_comparables3
  reg = FlexMock.new
  reg.should_receive(:active?).and_return { true }
  reg.should_receive(:may_violate_patent?).and_return { false }
  @seq.registration = reg
  atc = StubSequenceAtcClass.new
  @seq.atc_class = atc
  comp = ODDB::Composition.new
  subst1 = ODDB::Substance.new
  subst1.descriptions[:de] = 'CAPTOPRILUM'
  subst2 = ODDB::Substance.new
  subst2.descriptions[:de] = 'HYDROCHLOROTHIACIDUM'
  active_agent1 = ODDB::ActiveAgent.new('CAPTOPRILUM')
  active_agent2 = ODDB::ActiveAgent.new('HYDROCHLOROTHIACIDUM')
  active_agent1.substance = subst1
  active_agent2.substance = subst2
  active_agent1.composition = comp
  active_agent2.composition = comp
  @seq.compositions.push comp
  comp.galenic_form = StubSequenceGalenicForm.new
  comparable = ODDB::Sequence.new('02')
  comparable.registration = reg
  comparable.atc_class = atc
  comparable.compositions.push comp
  assert_equal([comparable], @seq.comparables)
end

- (Object) test_composition



324
325
326
327
328
329
# File 'test/test_model/sequence.rb', line 324

def test_composition
  comp1 = flexmock(:oid => 3)
  comp2 = flexmock(:oid => 5)
  @seq.compositions.push comp1, comp2
  assert_equal comp2, @seq.composition(5)
end

- (Object) test_composition_text



330
331
332
333
334
335
336
# File 'test/test_model/sequence.rb', line 330

def test_composition_text
  pac = flexmock :swissmedic_source => {:composition => 'composition'}
  @seq.packages.store '001', pac
  assert_equal 'composition', @seq.composition_text
  @seq.composition_text = 'composition text'
  assert_equal 'composition text', @seq.composition_text
end

- (Object) test_create_composition



337
338
339
340
341
342
343
344
# File 'test/test_model/sequence.rb', line 337

def test_create_composition
  comp1 = @seq.create_composition
  assert_instance_of Composition, comp1
  assert_equal [comp1], @seq.compositions
  comp2 = @seq.create_composition
  assert_instance_of Composition, comp2
  assert_equal [comp1, comp2], @seq.compositions
end

- (Object) test_create_package



345
346
347
348
349
350
351
352
# File 'test/test_model/sequence.rb', line 345

def test_create_package
  @seq.packages = {}
  package = @seq.create_package('023')
  assert_equal(@seq, package.sequence)
  assert_equal(package, @seq.package(23))
  package = @seq.create_package(32)
  assert_equal(package, @seq.package('032'))
end

- (Object) test_delete_composition



353
354
355
356
357
# File 'test/test_model/sequence.rb', line 353

def test_delete_composition
  @seq.compositions.push flexmock(:oid => 3)
  @seq.delete_composition 3
  assert_equal [], @seq.compositions
end

- (Object) test_delete_package



358
359
360
361
362
# File 'test/test_model/sequence.rb', line 358

def test_delete_package
  @seq.packages.store '003', 'package'
  @seq.delete_package '003'
  assert_equal({}, @seq.packages)
end

- (Object) test_dose



363
364
365
366
367
# File 'test/test_model/sequence.rb', line 363

def test_dose
  @seq.compositions.push flexmock(:doses => [Dose.new(10, 'mg'), Dose.new(10, 'mg')]),
                         flexmock(:doses => [Dose.new(20, 'mg')])
  assert_equal Dose.new(40, 'mg'), @seq.dose
end

- (Object) test_doses



368
369
370
371
372
373
# File 'test/test_model/sequence.rb', line 368

def test_doses
  @seq.compositions.push flexmock(:doses => [Dose.new(10, 'mg'), Dose.new(10, 'mg')]),
                         flexmock(:doses => [Dose.new(20, 'mg')])
  assert_equal [Dose.new(10, 'mg'), Dose.new(10, 'mg'), Dose.new(20, 'mg')],
               @seq.doses
end

- (Object) test_each



374
375
376
377
378
379
# File 'test/test_model/sequence.rb', line 374

def test_each
  res = []
  @seq.packages.update '003' => 'package1', '005' => 'package2'
  @seq.each_package do |pac| res.push pac end
  assert_equal %w{package1 package2}, res.sort
end

- (Object) test_factored_compositions



380
381
382
383
# File 'test/test_model/sequence.rb', line 380

def test_factored_compositions
  @seq.compositions.push 2.0, 4.0
  assert_equal [5.0, 10.0], @seq.factored_compositions(2.5)
end

- (Object) test_fix_pointers



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'test/test_model/sequence.rb', line 384

def test_fix_pointers
  reg = flexmock :pointer => Persistence::Pointer.new([:registration, '12345'])
  @seq.registration = reg
  pac1 = flexmock 'package'
  pac1.should_receive(:fix_pointers).times(1).and_return do
    assert true
  end
  @seq.packages.store '003', pac1
  comp1 = flexmock 'composition'
  comp1.should_receive(:fix_pointers).times(1).and_return do
    assert true
  end
  @seq.compositions.push comp1
  @seq.fix_pointers
end

- (Object) test_galenic_forms



417
418
419
420
421
422
423
424
# File 'test/test_model/sequence.rb', line 417

def test_galenic_forms
  comp1 = flexmock :galenic_form => 'form1'
  comp2 = flexmock :galenic_form => nil
  comp3 = flexmock :galenic_form => 'form2'
  comp4 = flexmock :galenic_form => 'form1'
  @seq.compositions.push comp1, comp2, comp3, comp4
  assert_equal ['form1', 'form2'], @seq.galenic_forms
end

- (Object) test_galenic_group



399
400
401
402
403
404
405
406
407
408
# File 'test/test_model/sequence.rb', line 399

def test_galenic_group
  comp1 = flexmock :galenic_group => 'group1'
  comp2 = flexmock :galenic_group => nil
  comp3 = flexmock :galenic_group => 'group2'
  comp4 = flexmock :galenic_group => 'group1'
  @seq.compositions.push comp1, comp2, comp4
  assert_equal 'group1', @seq.galenic_group
  @seq.compositions.push comp3
  assert_nil @seq.galenic_group
end

- (Object) test_galenic_groups



409
410
411
412
413
414
415
416
# File 'test/test_model/sequence.rb', line 409

def test_galenic_groups
  comp1 = flexmock :galenic_group => 'group1'
  comp2 = flexmock :galenic_group => nil
  comp3 = flexmock :galenic_group => 'group2'
  comp4 = flexmock :galenic_group => 'group1'
  @seq.compositions.push comp1, comp2, comp3, comp4
  assert_equal ['group1', 'group2'], @seq.galenic_groups
end

- (Object) test_has_patinfo



425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'test/test_model/sequence.rb', line 425

def test_has_patinfo
  comp1 = flexmock :disable_patinfo => false
  @seq.registration = flexmock :company => comp1
  assert_equal false, @seq.has_patinfo?
  @seq.pdf_patinfo = 'path-to.pdf'
  assert_equal true, @seq.has_patinfo?
  comp2 = flexmock :disable_patinfo => true
  @seq.registration = flexmock :company => comp2
  assert_equal false, @seq.has_patinfo?
  @seq.registration = flexmock :company => comp1
  @seq.deactivate_patinfo = @@today
  assert_equal false, @seq.has_patinfo?
end

- (Object) test_has_public_packages



438
439
440
441
442
443
# File 'test/test_model/sequence.rb', line 438

def test_has_public_packages
  @seq.packages.store '002', flexmock(:public? => false)
  assert_equal false, @seq.has_public_packages?
  @seq.packages.store '005', flexmock(:public? => true)
  assert_equal true, @seq.has_public_packages?
end

- (Object) test_iksnr



444
445
446
# File 'test/test_model/sequence.rb', line 444

def test_iksnr
  assert_respond_to(@seq, :iksnr)
end

- (Object) test_indication



447
448
449
450
451
452
453
# File 'test/test_model/sequence.rb', line 447

def test_indication
  assert_nil @seq.indication
  @seq.registration = flexmock :indication => 'registration indication'
  assert_equal 'registration indication', @seq.indication
  @seq.instance_variable_set '@indication', 'sequence indication'
  assert_equal 'sequence indication', @seq.indication
end

- (Object) test_indication_writer



454
455
456
457
458
459
460
# File 'test/test_model/sequence.rb', line 454

def test_indication_writer
  ind = flexmock 'indication'
  ind.should_receive(:add_sequence).with(@seq).times(1).and_return do
    assert true
  end
  @seq.indication = ind
end

- (Object) test_initalize



461
462
463
# File 'test/test_model/sequence.rb', line 461

def test_initalize
  assert_equal('01', @seq.seqnr)
end

- (Object) test_limitation_text



464
465
466
467
468
469
# File 'test/test_model/sequence.rb', line 464

def test_limitation_text
  assert_nil @seq.limitation_text
  @seq.packages.update '001' => flexmock(:limitation_text => nil),
                       '002' => flexmock(:limitation_text => 'text')
  assert_equal 'text', @seq.limitation_text
end

- (Object) test_limitation_text_count



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'test/test_model/sequence.rb', line 470

def test_limitation_text_count
  mock1 = Mock.new("packet_mock1")
  mock2 = Mock.new("packet_mock2")
  mock3 = Mock.new("packet_mock3")
  hash = {
    :mock1 => mock1,
    :mock2 => mock2,
    :mock3 => mock3,
  }
  @seq.packages = hash
  mock1.__next(:limitation_text) { "entry"}
  mock2.__next(:limitation_text) {}
  mock3.__next(:limitation_text) {}
  text_count = @seq.limitation_text_count
  mock1.__verify
  mock2.__verify
  mock3.__verify
  assert_equal(1, text_count)
end

- (Object) test_localized_name



489
490
491
492
493
494
# File 'test/test_model/sequence.rb', line 489

def test_localized_name
  @seq.name_base = 'Product'
  @seq.name_descr = 'Description'
  assert_equal 'Product, Description', @seq.localized_name(:de)
  assert_equal 'Product, Description', @seq.localized_name(:fr)
end

- (Object) test_longevity_writer



495
496
497
498
499
500
501
502
# File 'test/test_model/sequence.rb', line 495

def test_longevity_writer
  @seq.longevity = nil
  assert_nil @seq.longevity
  @seq.longevity = 5
  assert_equal 5, @seq.longevity
  @seq.longevity = 1
  assert_nil @seq.longevity
end

- (Object) test_match



503
504
505
506
507
508
509
# File 'test/test_model/sequence.rb', line 503

def test_match
  assert_nothing_raised{@seq.match('Aspirin')}
  assert_equal(nil, @seq.match('Aspirin'))
  @seq.name_base='Aspirin'
  assert_equal(MatchData, @seq.match('Aspirin').class)
  assert_equal(MatchData, @seq.match('aspirin').class)
end

- (Object) test_name_writer



510
511
512
513
514
515
# File 'test/test_model/sequence.rb', line 510

def test_name_writer
  @seq.name = "Aspirin, Tabletten"
  assert_equal("Aspirin, Tabletten", @seq.name)
  assert_equal("Aspirin", @seq.name_base)
  assert_equal("Tabletten", @seq.name_descr)
end

- (Object) test_out_of_trade



516
517
518
519
520
521
522
523
524
# File 'test/test_model/sequence.rb', line 516

def test_out_of_trade
  assert_equal true, @seq.out_of_trade
  @seq.packages.store '002', flexmock(:out_of_trade => false)
  assert_equal false, @seq.out_of_trade
  @seq.packages.store '003', flexmock(:out_of_trade => true)
  assert_equal false, @seq.out_of_trade
  @seq.packages.store '002', flexmock(:out_of_trade => true)
  assert_equal true, @seq.out_of_trade
end

- (Object) test_patinfo_writer



525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
# File 'test/test_model/sequence.rb', line 525

def test_patinfo_writer
  patinfo1 = StubPatinfo.new
  patinfo1.oid = 4
  patinfo2 = StubPatinfo.new
  patinfo2.oid = 5
  @seq.patinfo = patinfo1
  assert_equal(@seq, patinfo1.added)
  assert_nil(patinfo1.removed)
  @seq.patinfo = patinfo2
  assert_equal(@seq, patinfo1.removed)
  assert_equal(@seq, patinfo2.added)
  assert_equal(@seq.patinfo.oid, 5)
  assert_nil(patinfo2.removed)
  @seq.patinfo = nil
  assert_equal(@seq, patinfo2.removed)
end

- (Object) test_public



541
542
543
544
545
546
547
548
549
550
551
# File 'test/test_model/sequence.rb', line 541

def test_public
  @seq.registration = flexmock :public? => true, :active? => true
  assert_equal true, @seq.public?
  @seq.export_flag = true
  assert_equal false, @seq.public?
  @seq.export_flag = false
  @seq.registration = flexmock :public? => false, :active? => true
  assert_equal false, @seq.public?
  @seq.registration = flexmock :public? => true, :active? => false
  assert_equal false, @seq.public?
end

- (Object) test_public_package_count



561
562
563
564
565
566
567
568
# File 'test/test_model/sequence.rb', line 561

def test_public_package_count
  @seq.registration = flexmock :public? => true, :active? => true
  @seq.packages.store '002', flexmock(:public? => true)
  @seq.packages.store '003', flexmock(:public? => false)
  assert_equal 1, @seq.public_package_count
  @seq.export_flag = true
  assert_equal 0, @seq.public_package_count
end

- (Object) test_public_packages



552
553
554
555
556
557
558
559
560
# File 'test/test_model/sequence.rb', line 552

def test_public_packages
  @seq.registration = flexmock :public? => true, :active? => true
  pac1 = flexmock(:public? => true)
  @seq.packages.store '002', pac1
  @seq.packages.store '003', flexmock(:public? => false)
  assert_equal [pac1], @seq.public_packages
  @seq.export_flag = true
  assert_equal [], @seq.public_packages
end

- (Object) test_robust_adjust_types



569
570
571
572
573
574
575
576
577
578
# File 'test/test_model/sequence.rb', line 569

def test_robust_adjust_types
  values = {
    :dose =>  [123, 'fjdsfjdksah'],
  }
  result = {}
  assert_nothing_raised {
    result = @seq.adjust_types(values)
  }
  assert_equal(ODDB::Dose.new(123, nil), result[:dose])
end

- (Object) test_robust_adjust_types_fuzzy_retry



579
580
581
582
583
584
585
586
587
588
# File 'test/test_model/sequence.rb', line 579

def test_robust_adjust_types_fuzzy_retry
  values = {
    :dose =>  [123, 'mgkKo'],
  }
  result = {}
  assert_nothing_raised {
    result = @seq.adjust_types(values)
  }
  assert_equal(ODDB::Dose.new(123, 'mg'), result[:dose])
end

- (Object) test_route_of_administration



589
590
591
592
593
594
595
596
597
# File 'test/test_model/sequence.rb', line 589

def test_route_of_administration
  assert_nil @seq.route_of_administration
  @seq.compositions.push flexmock(:route_of_administration => 'O'),
                         flexmock(:route_of_administration => nil),
                         flexmock(:route_of_administration => 'O')
  assert_equal 'O', @seq.route_of_administration
  @seq.compositions.push flexmock(:route_of_administration => 'P')
  assert_nil @seq.route_of_administration
end

- (Object) test_search_terms



631
632
633
634
635
636
637
638
639
640
641
# File 'test/test_model/sequence.rb', line 631

def test_search_terms
  expected = [ 
    'Similasan', 'Kava',
    'KavaKava', 'Kava Kava', 
    'Similasan Kava',
    'Similasan KavaKava',
    'Similasan Kava Kava',
  ]
  @seq.name = 'Similasan Kava-Kava'
  assert_equal(expected, @seq.search_terms)
end

- (Object) test_seqnr_writer



598
599
600
601
602
603
604
605
606
607
608
609
# File 'test/test_model/sequence.rb', line 598

def test_seqnr_writer
  reg = flexmock 'registration',
                 :sequences => {'01' => @seq},
                 :pointer => Persistence::Pointer.new([:registration, '12345'])
  reg.should_receive(:sequence).with('02').and_return do
    assert true
    nil
  end
  @seq.registration = reg
  @seq.seqnr = '02'
  assert_equal({'02' => @seq}, reg.sequences)
end

- (Object) test_substance_names



620
621
622
623
624
625
626
627
628
629
630
# File 'test/test_model/sequence.rb', line 620

def test_substance_names
  active_agent1 = StubActiveAgent.new
  active_agent2 = StubActiveAgent.new
  active_agent1.substance = "Subst1"
  active_agent2.substance = "Subst2"
  comp = ODDB::Composition.new
  comp.active_agents.push active_agent1, active_agent2
  @seq.compositions.push comp
  expected = ["Subst1", "Subst2"]
  assert_equal(expected, @seq.substance_names)
end

- (Object) test_substances



610
611
612
613
614
615
616
617
618
619
# File 'test/test_model/sequence.rb', line 610

def test_substances
  active_agent1 = StubActiveAgent.new
  active_agent2 = StubActiveAgent.new
  active_agent1.substance = "Subst1"
  active_agent2.substance = "Subst2"
  comp = ODDB::Composition.new
  comp.active_agents.push active_agent1, active_agent2
  @seq.compositions.push comp
  assert_equal(["Subst1", "Subst2"], @seq.substances)
end

- (Object) test_violates_patent



642
643
644
645
646
647
648
649
650
# File 'test/test_model/sequence.rb', line 642

def test_violates_patent
  act = flexmock :substance => 'Substance', :chemical_substance => nil
  comp = flexmock :active_agents => [act]
  seq = flexmock :active_agents => [act]
  @seq.compositions.push comp
  assert_equal true, @seq._violates_patent?(seq)
  @seq.compositions.clear
  assert_equal false, @seq._violates_patent?(seq)
end