Class: ODDB::TestGalenicForm

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

Defined Under Namespace

Classes: StubApp, StubGroup, StubSequence

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



55
56
57
58
# File 'test/test_model/galenicform.rb', line 55

def setup
  @galform = ODDB::GalenicForm.new
  @galform.update_values('de'=>'Tabletten')
end

- (Object) teardown



59
60
61
# File 'test/test_model/galenicform.rb', line 59

def teardown
  ODBA.storage = nil
end

- (Object) test_adjust_types



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'test/test_model/galenicform.rb', line 62

def test_adjust_types
  app = StubApp.new
  group = app.galenic_group(2)
  pointer = ODDB::Persistence::Pointer.new([:galenic_group, 2])
  values = {
    :de             =>  'Augensalbe',
    :galenic_group  => pointer,
  }
  expected = {
    :de             =>  'Augensalbe',
    :galenic_group  => group,
  }
  result = @galform.adjust_types(values, app)
  assert_equal(expected, result)
end

- (Object) test_compare



77
78
79
80
81
82
# File 'test/test_model/galenicform.rb', line 77

def test_compare
  galform = ODDB::GalenicForm.new
  galform.update_values('de'=>'Suspension')
  assert_nothing_raised { galform <=> @galform }
  assert(@galform > galform, 'Tabletten was not > Suspension')
end

- (Object) test_equivalent_to



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'test/test_model/galenicform.rb', line 83

def test_equivalent_to
  group1 = StubGroup.new
  @galform.galenic_group = group1
  galform = ODDB::GalenicForm.new
  assert_not_equal(@galform, galform)
  assert(!@galform.equivalent_to?(galform), "The GalenicForms should not be equivalent")
  galform.galenic_group = group1
  assert_not_equal(@galform, galform)
  assert(@galform.equivalent_to?(galform), "The GalenicForms should be equivalent")
  assert(galform.equivalent_to?(@galform), "The GalenicForms should be equivalent")
  galform.galenic_group = StubGroup.new
  assert_not_equal(@galform, galform)
  assert(!@galform.equivalent_to?(galform), "The GalenicForms should not be equivalent")
end

- (Object) test_galenic_group_writer



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'test/test_model/galenicform.rb', line 97

def test_galenic_group_writer
  group1 = StubGroup.new
  assert_nil(group1.add_called)
  @galform.galenic_group = group1
  assert_equal(group1, @galform.galenic_group)
  assert_equal(@galform, group1.add_called)
  assert_equal([:parent, :galenic_form, @galform.oid], @galform.pointer)
  assert_nil(group1.remove_called)
  group2 = StubGroup.new
  @galform.galenic_group = group2
  assert_equal(@galform, group1.remove_called)
  assert_equal(@galform, group2.add_called)
end

- (Object) test_init



110
111
112
113
114
115
116
# File 'test/test_model/galenicform.rb', line 110

def test_init
  pointer = ODDB::Persistence::Pointer.new([:galenic_group, 1], [:galenic_form])
  @galform.pointer = pointer
  @galform.init(nil)
  expected = pointer.parent + [:galenic_form, @galform.oid]
  assert_equal(expected, @galform.pointer)
end

- (Object) test_merge



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'test/test_model/galenicform.rb', line 117

def test_merge
  other = GalenicForm.new
  other.update_values('de'=>'Filmtabletten')
  comp1 = flexmock :galenic_form => other, :odba_isolated_store => true
  comp2 = flexmock :galenic_form => 'something-else'
  seq1 = flexmock :compositions => [comp1]
  seq2 = flexmock :compositions => [comp2]
  other.sequences.push seq1, seq2
  comp1.should_receive(:galenic_form=).with(@galform).times(1).and_return do
    assert true
  end
  @galform.merge(other)
  assert_equal ['Filmtabletten'], @galform.synonyms
end

- (Object) test_remove_sequence1



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

def test_remove_sequence1
  a = StubSequence.new
  b = StubSequence.new
  c = StubSequence.new
  @galform.sequences = [a, b, c]
  @galform.remove_sequence(b)
  assert_equal([a, c], @galform.sequences)
end

- (Object) test_remove_sequence2



139
140
141
142
143
144
145
146
147
148
# File 'test/test_model/galenicform.rb', line 139

def test_remove_sequence2
  a = StubSequence.new
  b = StubSequence.new
  c = StubSequence.new
  @galform.sequences = [a, b, c]
  @galform.sequences.dup.each { |seq|
    @galform.remove_sequence(seq)
  }
  assert_equal(0, @galform.sequences.size)
end

- (Object) test_route_of_administration



149
150
151
152
153
154
# File 'test/test_model/galenicform.rb', line 149

def test_route_of_administration
  assert_nil @galform.route_of_administration
  @galform.instance_variable_set '@galenic_group',
                                 flexmock(:route_of_administration => 'O')
  assert_equal 'O', @galform.route_of_administration
end

- (Object) test_sequence_count



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'test/test_model/galenicform.rb', line 155

def test_sequence_count
  a = StubSequence.new
  b = StubSequence.new
  c = StubSequence.new
  assert_equal(0, @galform.sequence_count)
  @galform.add_sequence(a)
  assert_equal(1, @galform.sequence_count)
  @galform.add_sequence(b)
  assert_equal(2, @galform.sequence_count)
  @galform.remove_sequence(a)
  assert_equal(1, @galform.sequence_count)
  @galform.remove_sequence(b)
  assert_equal(0, @galform.sequence_count)
  @galform.remove_sequence(c)
  assert_equal(0, @galform.sequence_count)
end

- (Object) test_update_values



171
172
173
174
175
# File 'test/test_model/galenicform.rb', line 171

def test_update_values
  assert_equal({'de'=>'Tabletten'}, @galform.descriptions.to_hash)  
  @galform.update_values(:de => 'Filmtabletten')
  assert_equal({'de'=>'Filmtabletten'}, @galform.descriptions.to_hash)  
end