Class: ODDB::State::Substances::TestSubstanceState

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



17
18
19
20
21
22
# File 'test/test_state/substances/substance.rb', line 17

def setup
  @session = Mock.new('session')
  @model = Mock.new('model')
  @state = State::Substances::Substance.new(@session, @model)
  @state.extend(State::Admin::Root)
end

- (Object) teardown



23
24
25
26
# File 'test/test_state/substances/substance.rb', line 23

def teardown
  @session.__verify
  @model.__verify
end

- (Object) test_delete



27
28
29
30
# File 'test/test_state/substances/substance.rb', line 27

def test_delete
  @model.__next(:empty?) { false }
  @state.delete
end

- (Object) test_delete2



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'test/test_state/substances/substance.rb', line 31

def test_delete2
  app = Mock.new('app')
  @model.__next(:empty?) { true }
  @session.__next(:app) { app }
  @model.__next(:pointer) { 'model_pointer' }
  app.__next(:delete) { |pointer| 
    assert_equal('model_pointer', pointer)
  }
  @session.__next(:app) { app }
  app.__next(:substances) { [ ODDB::Substance.new ] } 
  @session.__next(:user_input) { nil }
  @state.delete
  app.__verify
end

- (Object) test_merge



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'test/test_state/substances/substance.rb', line 45

def test_merge
  app = Mock.new('app')
  substance = Mock.new('substance')
  @session.__next(:user_input) { |param|
    assert_equal(:substance_form, param)
    'substance'
  }
  @session.__next(:app) { app }
  app.__next(:substance) { |subs|
    assert_equal('substance', subs)
    substance
  }
  substance.__next(:has_connection_key?) { false }
  @session.__next(:app) { app }
  substance.__next(:pointer) { 'target_pointer' }
  @model.__next(:pointer) { 'source_pointer' }
  app.__next(:merge_substances) { |source, target|
    assert_equal('source_pointer', source)
    assert_equal('target_pointer', target)
  }
  @state.merge
  app.__verify
  substance.__verify
end

- (Object) test_merge2



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'test/test_state/substances/substance.rb', line 69

def test_merge2
  app = Mock.new('app')
  substance = Mock.new('substance')
  @session.__next(:user_input) { |param|
    assert_equal(:substance_form, param)
    'substance'
  }
  @session.__next(:app) { app }
  app.__next(:substance) { |subs|
    assert_equal('substance', subs)
    nil
  }
  @state.merge
  assert_equal([ :substance ], @state.errors.keys)
  app.__verify
  substance.__verify
end

- (Object) test_merge3



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'test/test_state/substances/substance.rb', line 86

def test_merge3
  app = Mock.new('app')
  substance = Mock.new('substance')
  @session.__next(:user_input) { |param|
    assert_equal(:substance_form, param)
    'substance'
  }
  @session.__next(:app) { app }
  app.__next(:substance) { |subs|
    assert_equal('substance', subs)
    @model
  }
  @state.merge
  assert_equal([ :substance ], @state.errors.keys)
  app.__verify
  substance.__verify
end

- (Object) test_update



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'test/test_state/substances/substance.rb', line 103

def test_update
  lookandfeel = Mock.new('lookandfeel')
  app = Mock.new('app')
  substance = Mock.new('substance')
  @session.__next(:lookandfeel) { lookandfeel }
  lookandfeel.__next(:languages) { ['de'] }
  @session.__next(:user_input) { |param|
    assert_equal(:de, param)
    'value'
  }
  @session.__next(:app) { app }
  app.__next(:substance) { |value|
    assert_equal('value', value)
    substance
  }
  @session.__next(:user_input) { |param|
    assert_equal(:en, param)
    'value'
  }
  @session.__next(:app) { app }
  app.__next(:substance) { |value|
    assert_equal('value', value)
    substance
  }
  @session.__next(:user_input) { |param|
    assert_equal(:lt, param)
    'value'
  }
  @session.__next(:app) { app }
  app.__next(:substance) { |value|
    assert_equal('value', value)
    substance
  }
  @state.update
  assert_equal(3, @state.errors.size)
  lookandfeel.__verify
  app.__verify
  substance.__verify
end

- (Object) test_update2



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'test/test_state/substances/substance.rb', line 142

def test_update2
  lookandfeel = Mock.new('lookandfeel')
  app = Mock.new('app')
  @session.__next(:lookandfeel) { lookandfeel }
  lookandfeel.__next(:languages) { ['de'] }
  @session.__next(:user_input) { |param|
    assert_equal(:de, param)
    'value'
  }
  @session.__next(:app) { app }
  app.__next(:substance) { |value|
    assert_equal('value', value)
    nil
  }
  @session.__next(:user_input) { |param|
    assert_equal(:en, param)
    'value'
  }
  @session.__next(:app) { app }
  app.__next(:substance) { |value|
    assert_equal('value', value)
    @model 
  }
  @session.__next(:user_input) { |param|
    assert_equal(:lt, param)
    'value'
  }
  @session.__next(:app) { app }
  app.__next(:substance) { |value|
    assert_equal('value', value)
    @model
  }
  @session.__next(:app) { app }
  @model.__next(:pointer) { 'model_pointer' }
  app.__next(:update) { |pointer, input| 
    assert_equal('model_pointer', pointer)
    expected = { "de"=>"value", "lt"=>"value", "en"=>"value" }
    assert_equal(expected, input)
  }
  @state.update
  assert_equal(0, @state.errors.size)
  lookandfeel.__verify
  app.__verify
end