@@ -60,7 +60,7 @@ def teardown
60
60
assert_not_nil flash [ :notice ]
61
61
end
62
62
63
- test "create.api " do
63
+ test "create.json " do
64
64
with_settings :rest_api_enabled => '1' do
65
65
poll = SchedulingPoll . find_by ( :issue => 1 )
66
66
assert_not_nil poll
@@ -70,11 +70,6 @@ def teardown
70
70
assert_equal 'exist' , json [ 'status' ]
71
71
assert_equal poll . id , json [ 'poll' ] [ 'id' ]
72
72
73
- post :create , :scheduling_poll => { :issue_id => 1 , :scheduling_poll_items_attributes => [ ] } , :format => :xml , :key => User . current . api_key
74
- assert_response :success
75
- assert_equal 'application/xml' , response . content_type
76
- assert_match /exist/ , response . body
77
-
78
73
assert poll . destroy
79
74
poll = nil
80
75
post :create , :scheduling_poll => { :issue_id => 1 , :scheduling_poll_items_attributes => [ { :text => "text1" , :position => 1 } , { :text => "text2" , :position => 2 } , { :text => "" , :position => 3 } ] } , :format => :json , :key => User . current . api_key
@@ -86,6 +81,17 @@ def teardown
86
81
json = ActiveSupport ::JSON . decode ( response . body )
87
82
assert_equal 'ok' , json [ 'status' ]
88
83
assert_equal poll . id , json [ 'poll' ] [ 'id' ]
84
+ end
85
+ end
86
+
87
+ test "create.xml" do
88
+ with_settings :rest_api_enabled => '1' do
89
+ poll = SchedulingPoll . find_by ( :issue => 1 )
90
+ assert_not_nil poll
91
+ post :create , :scheduling_poll => { :issue_id => 1 , :scheduling_poll_items_attributes => [ ] } , :format => :xml , :key => User . current . api_key
92
+ assert_response :success
93
+ assert_equal 'application/xml' , response . content_type
94
+ assert_match /exist/ , response . body
89
95
90
96
assert poll . destroy
91
97
poll = nil
@@ -121,6 +127,26 @@ def teardown
121
127
assert_not_nil flash [ :notice ]
122
128
end
123
129
130
+ test "update.json" do
131
+ with_settings :rest_api_enabled => '1' do
132
+ poll = SchedulingPoll . find_by ( :issue => 1 )
133
+ assert_not_nil poll
134
+ patch :update , :id => 1 , :scheduling_poll => { :issue_id => 1 , :scheduling_poll_items_attributes => [ { :id => 1 , :position => 1 } , { :id => 2 , :position => 2 , :_destroy => 1 } , { :id => 3 , :position => 3 , :_destroy => 0 } , { :text => "text" , :position => 4 } , { :text => "" , :position => 5 } ] } , :format => :json , :key => User . current . api_key
135
+ assert_response :success
136
+ assert_empty response . body
137
+ end
138
+ end
139
+
140
+ test "update.xml" do
141
+ with_settings :rest_api_enabled => '1' do
142
+ poll = SchedulingPoll . find_by ( :issue => 1 )
143
+ assert_not_nil poll
144
+ patch :update , :id => 1 , :scheduling_poll => { :issue_id => 1 , :scheduling_poll_items_attributes => [ { :id => 1 , :position => 1 } , { :id => 2 , :position => 2 , :_destroy => 1 } , { :id => 3 , :position => 3 , :_destroy => 0 } , { :text => "text" , :position => 4 } , { :text => "" , :position => 5 } ] } , :format => :xml , :key => User . current . api_key
145
+ assert_response :success
146
+ assert_empty response . body
147
+ end
148
+ end
149
+
124
150
test "show" do
125
151
get :show , :id => 1
126
152
assert_response :success
@@ -155,7 +181,7 @@ def teardown
155
181
156
182
get :show , :id => 1 , :format => :xml , :key => User . current . api_key
157
183
assert_response :success
158
- assert_equal 'application/xml' , @ response. content_type
184
+ assert_equal 'application/xml' , response . content_type
159
185
160
186
get :show , :id => 9999 , :format => :json , :key => User . current . api_key # not-exist issue
161
187
assert_response 404
@@ -165,6 +191,50 @@ def teardown
165
191
end
166
192
end
167
193
194
+ test "show_by_issue" do
195
+ get :show_by_issue , :issue_id => 1
196
+ assert_redirected_to :action => :show , :id => 1
197
+
198
+ get :show_by_issue , :issue_id => 9999 # not-exist issue
199
+ assert_response 404
200
+ end
201
+
202
+ test "show_by_issue.api" do
203
+ with_settings :rest_api_enabled => '1' do
204
+ get :show_by_issue , :issue_id => 1 , :format => :json , :key => User . current . api_key
205
+ assert_response :success
206
+ json = ActiveSupport ::JSON . decode ( response . body )
207
+ assert_kind_of Hash , json [ 'scheduling_poll' ]
208
+ assert_equal 1 , json [ 'scheduling_poll' ] [ 'id' ]
209
+ assert_equal 1 , json [ 'scheduling_poll' ] [ 'issue' ] [ 'id' ]
210
+ assert_kind_of Array , json [ 'scheduling_poll' ] [ 'scheduling_poll_items' ]
211
+ assert_equal 1 , json [ 'scheduling_poll' ] [ 'scheduling_poll_items' ] [ 0 ] [ 'id' ]
212
+ assert_equal SchedulingPollItem . find ( 1 ) . text , json [ 'scheduling_poll' ] [ 'scheduling_poll_items' ] [ 0 ] [ 'text' ]
213
+ assert_kind_of Array , json [ 'scheduling_poll' ] [ 'scheduling_poll_items' ] [ 0 ] [ 'scheduling_votes' ]
214
+ assert_equal 1 , json [ 'scheduling_poll' ] [ 'scheduling_poll_items' ] [ 0 ] [ 'scheduling_votes' ] [ 0 ] [ 'user' ] [ 'id' ]
215
+ assert_equal [ {
216
+ 'value' => 3 ,
217
+ 'text' => Setting . plugin_redmine_scheduling_poll [ "scheduling_vote_value_3" ] ,
218
+ } ] [ 0 ] , json [ 'scheduling_poll' ] [ 'scheduling_poll_items' ] [ 0 ] [ 'scheduling_votes' ] [ 0 ] [ 'value' ]
219
+ assert_equal 2 , json [ 'scheduling_poll' ] [ 'scheduling_poll_items' ] [ 0 ] [ 'scheduling_votes' ] [ 1 ] [ 'user' ] [ 'id' ]
220
+ assert_equal [ {
221
+ 'value' => 2 ,
222
+ 'text' => Setting . plugin_redmine_scheduling_poll [ "scheduling_vote_value_2" ] ,
223
+ } ] [ 0 ] , json [ 'scheduling_poll' ] [ 'scheduling_poll_items' ] [ 0 ] [ 'scheduling_votes' ] [ 1 ] [ 'value' ]
224
+ assert_response :success
225
+
226
+ get :show_by_issue , :issue_id => 1 , :format => :xml , :key => User . current . api_key
227
+ assert_response :success
228
+ assert_equal 'application/xml' , response . content_type
229
+
230
+ get :show_by_issue , :issue_id => 9999 , :format => :json , :key => User . current . api_key # not-exist issue
231
+ assert_response 404
232
+
233
+ get :show_by_issue , :issue_id => 9999 , :format => :xml , :key => User . current . api_key # not-exist issue
234
+ assert_response 404
235
+ end
236
+ end
237
+
168
238
test "vote" do
169
239
assert_equal nil , SchedulingPollItem . find ( 4 ) . vote_by_user ( User . current )
170
240
assert_equal nil , SchedulingPollItem . find ( 5 ) . vote_by_user ( User . current )
@@ -189,11 +259,55 @@ def teardown
189
259
assert_response 500
190
260
end
191
261
192
- test "show_by_issue" do
193
- get :show_by_issue , :issue_id => 1
194
- assert_redirected_to :action => :show , :id => 1
262
+ test "vote.json" do
263
+ with_settings :rest_api_enabled => '1' do
264
+ assert_equal nil , SchedulingPollItem . find ( 4 ) . vote_by_user ( User . current )
265
+ assert_equal nil , SchedulingPollItem . find ( 5 ) . vote_by_user ( User . current )
266
+ assert_equal nil , SchedulingPollItem . find ( 6 ) . vote_by_user ( User . current )
195
267
196
- get :show_by_issue , :issue_id => 9999 # not-exist issue
197
- assert_response 404
268
+ post :vote , :id => 2 , :scheduling_vote => { '4' => '0' , '5' => '1' , '6' => '2' } , :vote_comment => '' , :format => :json , :key => User . current . api_key
269
+ assert_response :success
270
+ assert_empty response . body
271
+ assert_equal nil , SchedulingPollItem . find ( 4 ) . vote_by_user ( User . current )
272
+ assert_equal 1 , SchedulingPollItem . find ( 5 ) . vote_value_by_user ( User . current )
273
+ assert_equal 2 , SchedulingPollItem . find ( 6 ) . vote_value_by_user ( User . current )
274
+
275
+ post :vote , :id => 2 , :scheduling_vote => { '4' => '2' , '5' => '1' , '6' => '0' } , :vote_comment => '**vote test msg**' , :format => :json , :key => User . current . api_key
276
+ assert_response :success
277
+ assert_empty response . body
278
+ assert_equal 2 , SchedulingPollItem . find ( 4 ) . vote_value_by_user ( User . current )
279
+ assert_equal 1 , SchedulingPollItem . find ( 5 ) . vote_value_by_user ( User . current )
280
+ assert_equal nil , SchedulingPollItem . find ( 6 ) . vote_by_user ( User . current )
281
+ # Journal does not work in the test (i.e. empty)
282
+
283
+ post :vote , :id => 2 , :scheduling_vote => { '4' => '2' , '5' => '1' , '6' => '0' } , :vote_comment => '' , :format => :json , :key => User . current . api_key # no-change
284
+ assert_response 422
285
+ end
286
+ end
287
+
288
+ test "vote.xml" do
289
+ with_settings :rest_api_enabled => '1' do
290
+ assert_equal nil , SchedulingPollItem . find ( 4 ) . vote_by_user ( User . current )
291
+ assert_equal nil , SchedulingPollItem . find ( 5 ) . vote_by_user ( User . current )
292
+ assert_equal nil , SchedulingPollItem . find ( 6 ) . vote_by_user ( User . current )
293
+
294
+ post :vote , :id => 2 , :scheduling_vote => { '4' => '0' , '5' => '1' , '6' => '2' } , :vote_comment => '' , :format => :xml , :key => User . current . api_key
295
+ assert_response :success
296
+ assert_empty response . body
297
+ assert_equal nil , SchedulingPollItem . find ( 4 ) . vote_by_user ( User . current )
298
+ assert_equal 1 , SchedulingPollItem . find ( 5 ) . vote_value_by_user ( User . current )
299
+ assert_equal 2 , SchedulingPollItem . find ( 6 ) . vote_value_by_user ( User . current )
300
+
301
+ post :vote , :id => 2 , :scheduling_vote => { '4' => '2' , '5' => '1' , '6' => '0' } , :vote_comment => '**vote test msg**' , :format => :xml , :key => User . current . api_key
302
+ assert_response :success
303
+ assert_empty response . body
304
+ assert_equal 2 , SchedulingPollItem . find ( 4 ) . vote_value_by_user ( User . current )
305
+ assert_equal 1 , SchedulingPollItem . find ( 5 ) . vote_value_by_user ( User . current )
306
+ assert_equal nil , SchedulingPollItem . find ( 6 ) . vote_by_user ( User . current )
307
+ # Journal does not work in the test (i.e. empty)
308
+
309
+ post :vote , :id => 2 , :scheduling_vote => { '4' => '2' , '5' => '1' , '6' => '0' } , :vote_comment => '' , :format => :xml , :key => User . current . api_key # no-change
310
+ assert_response 422
311
+ end
198
312
end
199
313
end
0 commit comments