Class: ODDB::State::Drugs::TestActiveAgentState

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_state/drugs/activeagent.rb

Defined Under Namespace

Classes: StubActiveAgent, StubApp, StubPointer, StubSequence, StubSession, StubSubstance

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



83
84
85
86
87
88
89
90
# File 'test/test_state/drugs/activeagent.rb', line 83

def setup
  @session = StubSession.new
  @activeagent = StubActiveAgent.new
  @activeagent.pointer = Persistence::Pointer.new(:sequence, :active_agent)
  @sequence = StubSequence.new
  @state = State::Drugs::ActiveAgent.new(@session, @activeagent)
  @session.app.sequence = @sequence
end

- (Object) test_substance_selection



144
145
146
147
148
149
150
151
152
# File 'test/test_state/drugs/activeagent.rb', line 144

def test_substance_selection
  sub2 = StubSubstance.new("Acidum Mefenanicum", true)
  sub4 = StubSubstance.new("Acidum Mefenanikum", true)
  sub5 = StubSubstance.new("Acidum Mephenanikum", true)
  @sequence.substances = [sub4]
  @session.app.soundex_substances = [ sub2, sub4, sub5 ]

  assert_equal([sub2, sub5], @state.substance_selection)
end

- (Object) test_update1



91
92
93
94
95
96
97
98
99
100
# File 'test/test_state/drugs/activeagent.rb', line 91

def test_update1
  @session.user_input = { :substance => '',  :dose => ''}
  newstate = @state.update
  assert_equal(true, @state.error?)
  assert_equal(@state, newstate)
  assert_equal(1, @state.errors.size)
  assert_equal(true, @state.errors.has_key?(:substance))
  assert_equal(false, @state.errors.has_key?(:dose))
  assert_equal(false, @session.app.update_called)
end

- (Object) test_update2



101
102
103
104
105
106
107
108
109
110
# File 'test/test_state/drugs/activeagent.rb', line 101

def test_update2
  @session.user_input = { 
    :substance => 'Acidum Mefenamicum',  
    :dose => '10 mg'
  }
  newstate = @state.update
  assert_equal(false, @state.error?)
  assert_equal(State::Drugs::SelectSubstance, newstate.class)
  assert_equal(false, @session.app.update_called)
end

- (Object) test_update3



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'test/test_state/drugs/activeagent.rb', line 111

def test_update3
  substances = {'Acidum Mefenamicum' => 'Acidum Mefenamicum'}
  @session.app.substances = substances
  @activeagent.active_agents = substances
  @session.user_input = { 
    :substance => 'Acidum Mefenamicum',  
    :dose => '10 mg'
  }
  newstate = @state.update
  assert_equal(true, @state.error?)
  assert_equal(@state, newstate)
  assert_equal(1, @state.errors.size)
  assert_equal(true, @state.errors.has_key?(:substance))
  assert_equal(false, @session.app.update_called)
end

- (Object) test_update4



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'test/test_state/drugs/activeagent.rb', line 126

def test_update4
  subst1 = StubSubstance.new('Acidum Mefenamicum', false)
  subst1.pointer = 'substance_pointer_1'
  subst2 = StubSubstance.new('Acidum Acetylsalicylicum', false)
  subst2.pointer = 'substance_pointer_2'
  substances = {'Acidum Mefenamicum' => subst1}
  @activeagent.active_agents = substances.dup
  substances.store('Acidum Acetylsalicylicum', subst2)
  @session.app.substances = substances
  @session.user_input = { 
    :substance => 'Acidum Acetylsalicylicum',  
    :dose => '10 mg'
  }
  newstate = @state.update
  assert_equal(false, @state.error?)
  assert_equal(@state, newstate)
  assert_equal(true, @session.app.update_called)
end