Class: TestAtcClass

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

Defined Under Namespace

Classes: StubSequence

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



33
34
35
# File 'test/test_model/atcclass.rb', line 33

def setup
  @atc_class = ODDB::AtcClass.new('N02BA01')
end

- (Object) test_active_packages



39
40
41
42
43
44
45
46
# File 'test/test_model/atcclass.rb', line 39

def test_active_packages
  seq1 = flexmock 'sequence1'
  seq2 = flexmock 'sequence2'
  seq1.should_receive(:public_packages).and_return ['package1', 'package2']
  seq2.should_receive(:public_packages).and_return ['package3']
  @atc_class.sequences.push seq1, seq2
  assert_equal ['package1', 'package2', 'package3'], @atc_class.active_packages
end

- (Object) test_add_sequence



47
48
49
50
51
52
# File 'test/test_model/atcclass.rb', line 47

def test_add_sequence
  @atc_class.sequences = []
  prod = StubSequence.new
  @atc_class.add_sequence(prod)
  assert_equal([prod], @atc_class.sequences)
end

- (Object) test_checkout



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'test/test_model/atcclass.rb', line 94

def test_checkout
  seq1 = flexmock 'sequence1'
  seq2 = flexmock 'sequence2'
  seq1.should_receive(:atc_class=).with(nil).times(1).and_return do
    @atc_class.sequences.delete(seq1)
    assert true
  end
  seq2.should_receive(:atc_class=).with(nil).times(1).and_return do
    @atc_class.sequences.delete(seq2)
    assert true
  end
  @atc_class.sequences.push seq1, seq2
  @atc_class.checkout
  assert_equal [], @atc_class.sequences
end

- (Object) test_company_filter_search



109
110
111
112
113
114
115
116
117
118
# File 'test/test_model/atcclass.rb', line 109

def test_company_filter_search
  seq1 = flexmock 'sequence1'
  seq2 = flexmock 'sequence2'
  seq1.should_receive(:company).and_return 'company1'
  seq2.should_receive(:company).and_return 'company2'
  @atc_class.sequences.push seq1, seq2
  filtered = @atc_class.company_filter_search('company1')
  assert_instance_of ODDB::AtcClass, filtered
  assert_equal [seq1], filtered.sequences
end

- (Object) test_create_ddd



131
132
133
134
135
136
# File 'test/test_model/atcclass.rb', line 131

def test_create_ddd
  pointer = ODDB::Persistence::Pointer.new([:atc_class, "A"])
  ddd = @atc_class.create_ddd('O')
  assert_instance_of(ODDB::AtcClass::DDD, ddd)
  assert_equal(ddd, @atc_class.ddd('O'))
end

- (Object) test_create_ddd_guidelines



125
126
127
128
129
130
# File 'test/test_model/atcclass.rb', line 125

def test_create_ddd_guidelines
  pointer = ODDB::Persistence::Pointer.new([:atc_class, "A"])
  document = @atc_class.create_ddd_guidelines
  assert_instance_of(ODDB::Text::Document, document)
  assert_equal(document, @atc_class.ddd_guidelines)
end

- (Object) test_create_guidelines



119
120
121
122
123
124
# File 'test/test_model/atcclass.rb', line 119

def test_create_guidelines
  pointer = ODDB::Persistence::Pointer.new([:atc_class, "A"])
  document = @atc_class.create_guidelines
  assert_instance_of(ODDB::Text::Document, document)
  assert_equal(document, @atc_class.guidelines)
end

- (Object) test_delete_ddd



180
181
182
183
184
185
186
187
188
# File 'test/test_model/atcclass.rb', line 180

def test_delete_ddd
  pointer = ODDB::Persistence::Pointer.new([:atc_class, "A"])
  ddd = @atc_class.create_ddd('O')
  assert_equal(ddd, @atc_class.ddd('O'))
  @atc_class.delete_ddd('P')
  assert_equal(ddd, @atc_class.ddd('O'))
  @atc_class.delete_ddd('O')
  assert_nil @atc_class.ddd('O')
end

- (Object) test_has_ddd



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'test/test_model/atcclass.rb', line 148

def test_has_ddd
  assert_equal(false, @atc_class.has_ddd?)
  @atc_class.ddds.store('O', :ddd)
  assert_equal(true, @atc_class.has_ddd?)
  @atc_class.ddds.delete('O')
  assert_equal(false, @atc_class.has_ddd?)
  @atc_class.ddd_guidelines = :foo
  assert_equal(true, @atc_class.has_ddd?)
  @atc_class.ddd_guidelines = nil
  assert_equal(false, @atc_class.has_ddd?)
  @atc_class.guidelines = :foo
  assert_equal(true, @atc_class.has_ddd?)
  @atc_class.guidelines = nil
  assert_equal(false, @atc_class.has_ddd?)
end

- (Object) test_initialize



36
37
38
# File 'test/test_model/atcclass.rb', line 36

def test_initialize
  assert_equal('N02BA01', @atc_class.code)
end

- (Object) test_package_count



69
70
71
72
73
74
75
76
# File 'test/test_model/atcclass.rb', line 69

def test_package_count
  seq1 = flexmock 'sequence1'
  seq2 = flexmock 'sequence2'
  seq1.should_receive(:public_package_count).and_return 2
  seq2.should_receive(:public_package_count).and_return 1
  @atc_class.sequences.push seq1, seq2
  assert_equal 3, @atc_class.package_count
end

- (Object) test_packages



59
60
61
62
63
64
65
66
67
68
# File 'test/test_model/atcclass.rb', line 59

def test_packages
  @atc_class.sequences = [
    StubSequence.new,
    StubSequence.new,
    StubSequence.new,
    StubSequence.new,
  ]
  packages = @atc_class.packages
  assert_equal(16, packages.size)
end

- (Object) test_parent_code



137
138
139
140
141
142
143
144
145
146
147
# File 'test/test_model/atcclass.rb', line 137

def test_parent_code
  assert_equal('N02BA', @atc_class.parent_code)
  level4 = ODDB::AtcClass.new('N02BA')
  assert_equal('N02B', level4.parent_code)
  level3 = ODDB::AtcClass.new('N02B')
  assert_equal('N02', level3.parent_code)
  level2 = ODDB::AtcClass.new('N02')
  assert_equal('N', level2.parent_code)
  level1 = ODDB::AtcClass.new('N')
  assert_equal(nil, level1.parent_code)
end

- (Object) test_pointer_descr



189
190
191
192
# File 'test/test_model/atcclass.rb', line 189

def test_pointer_descr
  @atc_class.update_values :de => 'Description'
  assert_equal 'Description (N02BA01)', @atc_class.pointer_descr
end

- (Object) test_remove_sequence



53
54
55
56
57
58
# File 'test/test_model/atcclass.rb', line 53

def test_remove_sequence
  prod = StubSequence.new
  @atc_class.sequences = [prod]
  @atc_class.remove_sequence(prod)
  assert_equal([], @atc_class.sequences)
end

- (Object) test_substances__1



163
164
165
166
167
168
169
170
# File 'test/test_model/atcclass.rb', line 163

def test_substances__1
  seq1 = StubSequence.new
  seq1.substances = ['amlodipin']
  seq2 = StubSequence.new
  seq2.substances = ['amlodipin']
  @atc_class.sequences = [seq1, seq2]
  assert_equal(['amlodipin'], @atc_class.substances)
end

- (Object) test_substances__2



171
172
173
174
175
176
177
178
179
# File 'test/test_model/atcclass.rb', line 171

def test_substances__2
  seq1 = StubSequence.new
  seq1.substances = ['amlodipin']
  seq2 = StubSequence.new
  seq2.substances = ['acidum mefenamicum']
  @atc_class.sequences = [seq1, seq2]
  assert_equal(['amlodipin', 'acidum mefenamicum'], 
    @atc_class.substances)
end

- (Object) test_update_description2



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'test/test_model/atcclass.rb', line 81

def test_update_description2
  values = {
    'de' =>  'eine Beschreibung',
  }
  @atc_class.update_values(values)
  assert_equal(values['de'], @atc_class.description('de'))
  values = {
    'de' =>  'eine andere Beschreibung',
  }
  pointer = ODDB::Persistence::Pointer.new()
  pointer.issue_update(@atc_class, values)
  assert_equal(values['de'], @atc_class.description('de'))
end

- (Object) test_update_values1



77
78
79
80
# File 'test/test_model/atcclass.rb', line 77

def test_update_values1
  @atc_class.descriptions.update_values({'de'=>'eine Beschreibung'})
  assert_equal('eine Beschreibung', @atc_class.description('de'))
end