Class: ODDB::State::Drugs::TestInitState

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

Defined Under Namespace

Classes: StubApp, StubHome, StubLookandfeel, StubPointer, StubSession, StubUser

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



100
101
102
103
# File 'test/test_state/drugs/init.rb', line 100

def setup
  @session = StubSession.new
  @state = State::Drugs::Init.new(@session, @session)
end

- (Object) test_compare_entries



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

def test_compare_entries
  state = State::Drugs::Init.new(@session, [1,11,2,22,3,33])
  state.sortby = [:to_s]
  assert_equal(-1, state.compare_entries(11,2))
  state.sortby = [:to_f]
  assert_equal(1, state.compare_entries(11,2))
  state.sortby = [:to_s]
  assert_equal(0, state.compare_entries('a', ''))
end

- (Object) test_get_sortby



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'test/test_state/drugs/init.rb', line 118

def test_get_sortby
  state = State::Drugs::Init.new(@session, [1,11,2,22,3,33])
  @session.user_input = { :sortvalue => :to_s }
  state.get_sortby!
  assert_equal([:to_s], state.sortby)
  assert_equal(nil, state.sort_reverse)
  @session.user_input = { :sortvalue => :to_i }
  state.get_sortby!
  assert_equal([:to_i, :to_s], state.sortby)
  assert_equal(nil, state.sort_reverse)
  @session.user_input = { :sortvalue => :to_i }
  state.get_sortby!
  assert_equal([:to_i, :to_s], state.sortby)
  assert_equal(true, state.sort_reverse)
  @session.user_input = { :sortvalue => :to_s }
  state.get_sortby!
  assert_equal([:to_s, :to_i], state.sortby)
  assert_equal(nil, state.sort_reverse)
  @session.user_input = { :sortvalue => :to_f }
  state.get_sortby!
  assert_equal([:to_f, :to_s, :to_i], state.sortby)
  assert_equal(true, state.sort_reverse)
  @session.user_input = { :sortvalue => :to_f }
  state.get_sortby!
  assert_equal([:to_f, :to_s, :to_i], state.sortby)
  assert_equal(false, state.sort_reverse)
end

- (Object) test_init_state



104
105
106
# File 'test/test_state/drugs/init.rb', line 104

def test_init_state
  assert_equal(View::Search, @state.view.class)
end

- (Object) test_sort



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'test/test_state/drugs/init.rb', line 154

def test_sort
  state = State::Drugs::Init.new(@session, [1,11,2,22,3,33])
  @session.user_input = { :sortvalue => :to_i }
  state.sort
  assert_equal([:to_i], state.sortby)
  expected = [1,2,3,11,22,33]
  assert_equal(expected, state.model)
  state.sort
  assert_equal(expected.reverse, state.model)
  @session.user_input = { :sortvalue => :to_f }
  state.sort
  assert_equal(expected.reverse, state.model)
  state.sort
  @session.user_input = { :sortvalue => :to_s }
  state.sort
  expected = [1,11,2,22,3,33]
  assert_equal(expected, state.model)
end

- (Object) test_trigger_global



107
108
109
110
111
# File 'test/test_state/drugs/init.rb', line 107

def test_trigger_global
  newstate = @state.trigger(:login_form)
  assert_equal(State::Admin::, newstate.class)
  assert_equal(StubHome, newstate.trigger(:login).class)
end

- (Object) test_trigger_resolve



112
113
114
115
116
117
# File 'test/test_state/drugs/init.rb', line 112

def test_trigger_resolve
  session = StubSession.new
  state = State::Drugs::Init.new(session, session)
  newstate = state.trigger(:resolve)
  assert_equal(StubResolvedState, newstate.class)
end