Class: ODDB::TestNarcotic

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



15
16
17
# File 'test/test_model/narcotic.rb', line 15

def setup
  @narcotic = Narcotic.new
end

- (Object) test_add_package



26
27
28
29
30
31
32
33
34
35
# File 'test/test_model/narcotic.rb', line 26

def test_add_package
  narc = FlexMock.new
  res = @narcotic.add_package(narc)
  assert_equal([narc], @narcotic.packages)
  assert_equal(narc, res)
  narc2 = FlexMock.new
  res = @narcotic.add_package(narc2)
  assert_equal([narc, narc2], @narcotic.packages)
  assert_equal(narc2, res)
end

- (Object) test_add_substance



36
37
38
39
40
41
42
# File 'test/test_model/narcotic.rb', line 36

def test_add_substance
  sub = flexmock :odba_store => true
  @narcotic.add_substance sub
  assert_equal [sub], @narcotic.substances
  @narcotic.add_substance sub
  assert_equal [sub], @narcotic.substances
end

- (Object) test_casrn



43
44
45
46
# File 'test/test_model/narcotic.rb', line 43

def test_casrn
  @narcotic.substances.push flexmock(:casrn => nil), flexmock(:casrn => '123')
  assert_equal '123', @narcotic.casrn
end

- (Object) test_checkout



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'test/test_model/narcotic.rb', line 47

def test_checkout
  sub1 = flexmock :odba_store => true
  sub1.should_receive(:narcotic=).with(nil).times(1).and_return do
    @narcotic.remove_substance sub1
    assert true
  end
  sub2 = flexmock :odba_store => true
  sub2.should_receive(:narcotic=).with(nil).times(1).and_return do
    @narcotic.remove_substance sub2
    assert true
  end
  @narcotic.substances.push sub1, sub2
  pac1 = flexmock :odba_store => true
  pac1.should_receive(:remove_narcotic).with(@narcotic).times(1).and_return do
    @narcotic.remove_package pac1
    assert true
  end
  pac2 = flexmock :odba_store => true
  pac2.should_receive(:remove_narcotic).with(@narcotic).times(1).and_return do
    @narcotic.remove_package pac2
    assert true
  end
  @narcotic.packages.push pac1, pac2
  @narcotic.checkout
  assert_equal [], @narcotic.substances
  assert_equal [], @narcotic.packages
end

- (Object) test_create_reservation_text



74
75
76
77
78
# File 'test/test_model/narcotic.rb', line 74

def test_create_reservation_text
  txt = @narcotic.create_reservation_text
  assert_instance_of Text::Document, txt
  assert_equal txt, @narcotic.reservation_text
end

- (Object) test_init



18
19
20
21
22
23
24
25
# File 'test/test_model/narcotic.rb', line 18

def test_init
  ptr = Persistence::Pointer.new :narcotic
  @narcotic.pointer = ptr
  @narcotic.init
  assert_equal Persistence::Pointer.new([:narcotic, @narcotic.oid]),
               @narcotic.pointer
  assert_equal ptr, @narcotic.pointer
end

- (Object) test_pointer_descr



79
80
81
82
83
84
# File 'test/test_model/narcotic.rb', line 79

def test_pointer_descr
  sub1 = flexmock :to_s => 'Some Substance'
  sub2 = flexmock :to_s => 'Another Substance'
  @narcotic.substances.push sub1, sub2
  assert_equal 'Another Substance', @narcotic.pointer_descr
end

- (Object) test_remove_package



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'test/test_model/narcotic.rb', line 85

def test_remove_package
  narc = FlexMock.new
  narc2 = FlexMock.new
  @narcotic.packages.push(narc)
  @narcotic.packages.push(narc2)
  res = @narcotic.remove_package(narc)
  assert_equal([narc2], @narcotic.packages)
  assert_equal(narc, res)
  res = @narcotic.remove_package(narc)
  assert_equal([narc2], @narcotic.packages)
  assert_equal(nil, res)
  res = @narcotic.remove_package(narc2)
  assert_equal([], @narcotic.packages)
  assert_equal(narc2, res)
end

- (Object) test_remove_substance



100
101
102
103
104
105
106
107
# File 'test/test_model/narcotic.rb', line 100

def test_remove_substance
  sub = flexmock 'substance'
  @narcotic.substances.push sub
  @narcotic.remove_substance sub
  assert_equal [], @narcotic.substances
  @narcotic.remove_substance sub
  assert_equal [], @narcotic.substances
end

- (Object) test_swissmedic_codes



108
109
110
111
112
113
# File 'test/test_model/narcotic.rb', line 108

def test_swissmedic_codes
  sub1 = flexmock :swissmedic_code => '4321'
  sub2 = flexmock :swissmedic_code => '1234'
  @narcotic.substances.push sub1, sub2
  assert_equal %w{4321 1234}, @narcotic.swissmedic_codes
end

- (Object) test_to_s



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

def test_to_s
  sub1 = flexmock :to_s => 'Some Substance'
  sub2 = flexmock :to_s => 'Another Substance'
  @narcotic.substances.push sub1, sub2
  assert_equal 'Another Substance', @narcotic.to_s
end