@@ -29,6 +29,8 class Redmine::ApiTest::HttpBasicLoginTest < Redmine::ApiTest::Base | |||
|
29 | 29 | def setup |
|
30 | 30 | Setting.rest_api_enabled = '1' |
|
31 | 31 | Setting.login_required = '1' |
|
32 | project = Project.find('onlinestore') | |
|
33 | EnabledModule.create(:project => project, :name => 'news') | |
|
32 | 34 | end |
|
33 | 35 | |
|
34 | 36 | def teardown |
@@ -36,19 +38,6 class Redmine::ApiTest::HttpBasicLoginTest < Redmine::ApiTest::Base | |||
|
36 | 38 | Setting.login_required = '0' |
|
37 | 39 | end |
|
38 | 40 | |
|
39 | # Using the NewsController because it's a simple API. | |
|
40 | context "get /news" do | |
|
41 | setup do | |
|
42 | project = Project.find('onlinestore') | |
|
43 | EnabledModule.create(:project => project, :name => 'news') | |
|
44 | end | |
|
45 | ||
|
46 | context "in :xml format" do | |
|
47 | 41 |
|
|
48 | end | |
|
49 | ||
|
50 | context "in :json format" do | |
|
51 | 42 |
|
|
52 | 43 |
|
|
53 | end | |
|
54 | end |
@@ -36,15 +36,6 class Redmine::ApiTest::HttpBasicLoginWithApiTokenTest < Redmine::ApiTest::Base | |||
|
36 | 36 | Setting.login_required = '0' |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | # Using the NewsController because it's a simple API. | |
|
40 | context "get /news" do | |
|
41 | ||
|
42 | context "in :xml format" do | |
|
43 | 39 |
|
|
44 | end | |
|
45 | ||
|
46 | context "in :json format" do | |
|
47 | 40 |
|
|
48 | 41 |
|
|
49 | end | |
|
50 | end |
@@ -48,45 +48,69 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
48 | 48 | Setting.rest_api_enabled = '1' |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | context "/issues" do | |
|
52 | 51 |
|
|
53 | 52 |
|
|
54 | 53 |
|
|
54 | should_allow_api_authentication(:get, "/projects/private-child/issues.json") | |
|
55 | 55 | |
|
56 | should "contain metadata" do | |
|
57 | get '/issues.xml' | |
|
56 | should_allow_api_authentication(:get, "/issues/6.xml") | |
|
57 | should_allow_api_authentication(:get, "/issues/6.json") | |
|
58 | 58 | |
|
59 | assert_select 'issues[type=array][total_count=?][limit="25"][offset="0"]', assigns(:issue_count).to_s | |
|
60 | end | |
|
59 | should_allow_api_authentication( | |
|
60 | :post, | |
|
61 | '/issues.xml', | |
|
62 | {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, | |
|
63 | {:success_code => :created} | |
|
64 | ) | |
|
65 | should_allow_api_authentication(:post, | |
|
66 | '/issues.json', | |
|
67 | {:issue => {:project_id => 1, :subject => 'API test', | |
|
68 | :tracker_id => 2, :status_id => 3}}, | |
|
69 | {:success_code => :created}) | |
|
61 | 70 | |
|
62 | context "with offset and limit" do | |
|
63 | should "use the params" do | |
|
64 | get '/issues.xml?offset=2&limit=3' | |
|
71 | should_allow_api_authentication(:put, | |
|
72 | '/issues/6.xml', | |
|
73 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
|
74 | {:success_code => :ok}) | |
|
75 | should_allow_api_authentication(:put, | |
|
76 | '/issues/6.json', | |
|
77 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
|
78 | {:success_code => :ok}) | |
|
65 | 79 | |
|
66 | assert_equal 3, assigns(:limit) | |
|
67 | assert_equal 2, assigns(:offset) | |
|
68 | assert_select 'issues issue', 3 | |
|
69 | end | |
|
80 | should_allow_api_authentication(:delete, | |
|
81 | '/issues/6.xml', | |
|
82 | {}, | |
|
83 | {:success_code => :ok}) | |
|
84 | should_allow_api_authentication(:delete, | |
|
85 | '/issues/6.json', | |
|
86 | {}, | |
|
87 | {:success_code => :ok}) | |
|
88 | ||
|
89 | test "GET /issues.xml should contain metadata" do | |
|
90 | get '/issues.xml' | |
|
91 | assert_select 'issues[type=array][total_count=?][limit="25"][offset="0"]', | |
|
92 | assigns(:issue_count).to_s | |
|
70 | 93 |
|
|
71 | 94 | |
|
72 | context "with nometa param" do | |
|
73 | should "not contain metadata" do | |
|
95 | test "GET /issues.xml with nometa param should not contain metadata" do | |
|
74 | 96 |
|
|
75 | ||
|
76 | 97 |
|
|
77 | 98 |
|
|
78 | end | |
|
79 | 99 | |
|
80 | context "with nometa header" do | |
|
81 | should "not contain metadata" do | |
|
100 | test "GET /issues.xml with nometa header should not contain metadata" do | |
|
82 | 101 |
|
|
83 | ||
|
84 | 102 |
|
|
85 | 103 |
|
|
104 | ||
|
105 | test "GET /issues.xml with offset and limit" do | |
|
106 | get '/issues.xml?offset=2&limit=3' | |
|
107 | ||
|
108 | assert_equal 3, assigns(:limit) | |
|
109 | assert_equal 2, assigns(:offset) | |
|
110 | assert_select 'issues issue', 3 | |
|
86 | 111 |
|
|
87 | 112 | |
|
88 |
|
|
|
89 | should "display relations" do | |
|
113 | test "GET /issues.xml with relations" do | |
|
90 | 114 |
|
|
91 | 115 | |
|
92 | 116 |
|
@@ -102,46 +126,41 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
102 | 126 |
|
|
103 | 127 |
|
|
104 | 128 |
|
|
105 | end | |
|
106 | 129 | |
|
107 |
|
|
|
108 | should "return errors" do | |
|
130 | test "GET /issues.xml with invalid query params" do | |
|
109 | 131 |
|
|
110 | 132 | |
|
111 | 133 |
|
|
112 | 134 |
|
|
113 | 135 |
|
|
114 | 136 |
|
|
115 | end | |
|
116 | 137 | |
|
117 |
|
|
|
118 | should "show only issues with the custom field value" do | |
|
138 | test "GET /issues.xml with custom field filter" do | |
|
119 | 139 |
|
|
120 |
|
|
|
121 | :v => {:cf_1 => ['MySQL']}} | |
|
140 | {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}} | |
|
141 | ||
|
122 | 142 |
|
|
123 | 143 |
|
|
124 | 144 |
|
|
145 | assert expected_ids.any? | |
|
146 | ||
|
125 | 147 |
|
|
126 | 148 |
|
|
127 | 149 |
|
|
128 | 150 |
|
|
129 | end | |
|
130 | 151 | |
|
131 |
|
|
|
132 | should "show only issues with the custom field value" do | |
|
152 | test "GET /issues.xml with custom field filter (shorthand method)" do | |
|
133 | 153 |
|
|
134 | 154 | |
|
135 | 155 |
|
|
136 | 156 |
|
|
137 | 157 |
|
|
158 | assert expected_ids.any? | |
|
138 | 159 | |
|
139 | 160 |
|
|
140 | 161 |
|
|
141 | 162 |
|
|
142 | 163 |
|
|
143 | end | |
|
144 | end | |
|
145 | 164 | |
|
146 | 165 | def test_index_should_include_issue_attributes |
|
147 | 166 | get '/issues.xml' |
@@ -171,24 +190,18 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
171 | 190 | assert_select 'issues>issue', :count => 2 |
|
172 | 191 | end |
|
173 | 192 | |
|
174 | context "/index.json" do | |
|
175 | should_allow_api_authentication(:get, "/projects/private-child/issues.json") | |
|
176 | end | |
|
177 | ||
|
178 | context "/index.xml with filter" do | |
|
179 | should "show only issues with the status_id" do | |
|
193 | test "GET /issues.xml with filter" do | |
|
180 | 194 |
|
|
181 | 195 | |
|
182 | 196 |
|
|
197 | assert expected_ids.any? | |
|
183 | 198 | |
|
184 | 199 |
|
|
185 | 200 |
|
|
186 | 201 |
|
|
187 | 202 |
|
|
188 | end | |
|
189 | 203 | |
|
190 |
|
|
|
191 | should "show only issues with the status_id" do | |
|
204 | test "GET /issues.json with filter" do | |
|
192 | 205 |
|
|
193 | 206 | |
|
194 | 207 |
|
@@ -197,21 +210,7 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
197 | 210 |
|
|
198 | 211 |
|
|
199 | 212 | |
|
200 | end | |
|
201 | ||
|
202 | # Issue 6 is on a private project | |
|
203 | context "/issues/6.xml" do | |
|
204 | should_allow_api_authentication(:get, "/issues/6.xml") | |
|
205 | end | |
|
206 | ||
|
207 | context "/issues/6.json" do | |
|
208 | should_allow_api_authentication(:get, "/issues/6.json") | |
|
209 | end | |
|
210 | ||
|
211 | context "GET /issues/:id" do | |
|
212 | context "with journals" do | |
|
213 | context ".xml" do | |
|
214 | should "display journals" do | |
|
213 | test "GET /issues/:id.xml with journals" do | |
|
215 | 214 |
|
|
216 | 215 | |
|
217 | 216 |
|
@@ -225,12 +224,8 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
225 | 224 |
|
|
226 | 225 |
|
|
227 | 226 |
|
|
228 | end | |
|
229 | end | |
|
230 | 227 | |
|
231 |
|
|
|
232 | context ".xml" do | |
|
233 | should "display custom fields" do | |
|
228 | test "GET /issues/:id.xml with custom fields" do | |
|
234 | 229 |
|
|
235 | 230 | |
|
236 | 231 |
|
@@ -238,25 +233,18 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
238 | 233 |
|
|
239 | 234 |
|
|
240 | 235 |
|
|
241 | ||
|
242 | 236 |
|
|
243 | 237 |
|
|
244 | 238 |
|
|
245 | 239 |
|
|
246 | end | |
|
247 | end | |
|
248 | 240 | |
|
249 |
|
|
|
250 | setup do | |
|
241 | test "GET /issues/:id.xml with multi custom fields" do | |
|
251 | 242 |
|
|
252 | 243 |
|
|
253 | 244 |
|
|
254 | 245 |
|
|
255 | 246 |
|
|
256 | end | |
|
257 | 247 | |
|
258 | context ".xml" do | |
|
259 | should "display custom fields" do | |
|
260 | 248 |
|
|
261 | 249 |
|
|
262 | 250 | |
@@ -265,7 +253,6 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
265 | 253 |
|
|
266 | 254 |
|
|
267 | 255 |
|
|
268 | ||
|
269 | 256 |
|
|
270 | 257 |
|
|
271 | 258 |
|
@@ -273,12 +260,17 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
273 | 260 |
|
|
274 | 261 |
|
|
275 | 262 |
|
|
276 | end | |
|
277 | 263 | |
|
278 | context ".json" do | |
|
279 | should "display custom fields" do | |
|
264 | test "GET /issues/:id.json with multi custom fields" do | |
|
265 | field = CustomField.find(1) | |
|
266 | field.update_attribute :multiple, true | |
|
267 | issue = Issue.find(3) | |
|
268 | issue.custom_field_values = {1 => ['MySQL', 'Oracle']} | |
|
269 | issue.save! | |
|
270 | ||
|
280 | 271 |
|
|
281 | 272 |
|
|
273 | ||
|
282 | 274 |
|
|
283 | 275 |
|
|
284 | 276 |
|
@@ -286,20 +278,14 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
286 | 278 |
|
|
287 | 279 |
|
|
288 | 280 |
|
|
289 | end | |
|
290 | end | |
|
291 | 281 | |
|
292 |
|
|
|
293 | setup do | |
|
282 | test "GET /issues/:id.xml with empty value for multi custom field" do | |
|
294 | 283 |
|
|
295 | 284 |
|
|
296 | 285 |
|
|
297 | 286 |
|
|
298 | 287 |
|
|
299 | end | |
|
300 | 288 | |
|
301 | context ".xml" do | |
|
302 | should "display custom fields" do | |
|
303 | 289 |
|
|
304 | 290 | |
|
305 | 291 |
|
@@ -307,7 +293,6 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
307 | 293 |
|
|
308 | 294 |
|
|
309 | 295 |
|
|
310 | ||
|
311 | 296 |
|
|
312 | 297 |
|
|
313 | 298 |
|
@@ -315,10 +300,14 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
315 | 300 |
|
|
316 | 301 |
|
|
317 | 302 |
|
|
318 | end | |
|
319 | 303 | |
|
320 | context ".json" do | |
|
321 | should "display custom fields" do | |
|
304 | test "GET /issues/:id.json with empty value for multi custom field" do | |
|
305 | field = CustomField.find(1) | |
|
306 | field.update_attribute :multiple, true | |
|
307 | issue = Issue.find(3) | |
|
308 | issue.custom_field_values = {1 => ['']} | |
|
309 | issue.save! | |
|
310 | ||
|
322 | 311 |
|
|
323 | 312 |
|
|
324 | 313 |
|
@@ -328,12 +317,8 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
328 | 317 |
|
|
329 | 318 |
|
|
330 | 319 |
|
|
331 | end | |
|
332 | end | |
|
333 | 320 | |
|
334 |
|
|
|
335 | context ".xml" do | |
|
336 | should "display attachments" do | |
|
321 | test "GET /issues/:id.xml with attachments" do | |
|
337 | 322 |
|
|
338 | 323 | |
|
339 | 324 |
|
@@ -344,61 +329,24 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
344 | 329 |
|
|
345 | 330 |
|
|
346 | 331 |
|
|
347 | end | |
|
348 | end | |
|
349 | 332 | |
|
350 |
|
|
|
351 | setup do | |
|
352 | @c1 = Issue.create!( | |
|
353 | :status_id => 1, :subject => "child c1", | |
|
354 | :tracker_id => 1, :project_id => 1, :author_id => 1, | |
|
355 | :parent_issue_id => 1 | |
|
356 | ) | |
|
357 | @c2 = Issue.create!( | |
|
358 | :status_id => 1, :subject => "child c2", | |
|
359 | :tracker_id => 1, :project_id => 1, :author_id => 1, | |
|
360 | :parent_issue_id => 1 | |
|
361 | ) | |
|
362 | @c3 = Issue.create!( | |
|
363 | :status_id => 1, :subject => "child c3", | |
|
364 | :tracker_id => 1, :project_id => 1, :author_id => 1, | |
|
365 | :parent_issue_id => @c1.id | |
|
366 | ) | |
|
367 | end | |
|
368 | ||
|
369 | context ".xml" do | |
|
370 | should "display children" do | |
|
371 | get '/issues/1.xml?include=children' | |
|
333 | test "GET /issues/:id.xml with subtasks" do | |
|
334 | issue = Issue.generate_with_descendants!(:project_id => 1) | |
|
335 | get "/issues/#{issue.id}.xml?include=children" | |
|
372 | 336 | |
|
373 | 337 |
|
|
374 | 338 |
|
|
375 |
|
|
|
376 | assert_select 'subject', :text => 'child c1' | |
|
377 | assert_select 'children' do | |
|
378 | assert_select 'issue[id=?]', @c3.id.to_s | |
|
379 | end | |
|
380 | end | |
|
339 | assert_select 'issue children', 1 | |
|
381 | 340 |
|
|
382 | 341 |
|
|
383 | 342 | |
|
384 | context ".json" do | |
|
385 | should "display children" do | |
|
386 |
|
|
|
343 | test "GET /issues/:id.json with subtasks" do | |
|
344 | issue = Issue.generate_with_descendants!(:project_id => 1) | |
|
345 | get "/issues/#{issue.id}.json?include=children" | |
|
387 | 346 | |
|
388 | 347 |
|
|
389 | assert_equal([ | |
|
390 | { | |
|
391 | 'id' => @c1.id, 'subject' => 'child c1', 'tracker' => {'id' => 1, 'name' => 'Bug'}, | |
|
392 | 'children' => [{'id' => @c3.id, 'subject' => 'child c3', | |
|
393 | 'tracker' => {'id' => 1, 'name' => 'Bug'} }] | |
|
394 | }, | |
|
395 | { 'id' => @c2.id, 'subject' => 'child c2', 'tracker' => {'id' => 1, 'name' => 'Bug'} } | |
|
396 | ], | |
|
397 | json['issue']['children']) | |
|
398 | end | |
|
399 | end | |
|
400 | end | |
|
401 | end | |
|
348 | assert_equal 2, json['issue']['children'].size | |
|
349 | assert_equal 1, json['issue']['children'].select {|child| child.key?('children')}.size | |
|
402 | 350 | end |
|
403 | 351 | |
|
404 | 352 | def test_show_should_include_issue_attributes |
@@ -421,14 +369,7 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
421 | 369 | end |
|
422 | 370 | end |
|
423 | 371 | |
|
424 | context "POST /issues.xml" do | |
|
425 | should_allow_api_authentication( | |
|
426 | :post, | |
|
427 | '/issues.xml', | |
|
428 | {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, | |
|
429 | {:success_code => :created} | |
|
430 | ) | |
|
431 | should "create an issue with the attributes" do | |
|
372 | test "POST /issues.xml should create an issue with the attributes" do | |
|
432 | 373 |
|
|
433 | 374 |
|
|
434 | 375 |
|
@@ -444,7 +385,6 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
444 | 385 |
|
|
445 | 386 |
|
|
446 | 387 |
|
|
447 | end | |
|
448 | 388 | |
|
449 | 389 | test "POST /issues.xml with watcher_user_ids should create issue with watchers" do |
|
450 | 390 | assert_difference('Issue.count') do |
@@ -458,24 +398,15 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
458 | 398 | assert_equal [1, 3], issue.watcher_user_ids.sort |
|
459 | 399 | end |
|
460 | 400 | |
|
461 |
|
|
|
462 | should "have an errors tag" do | |
|
401 | test "POST /issues.xml with failure should return errors" do | |
|
463 | 402 |
|
|
464 | 403 |
|
|
465 | 404 |
|
|
466 | 405 | |
|
467 | 406 |
|
|
468 | 407 |
|
|
469 | end | |
|
470 | ||
|
471 | context "POST /issues.json" do | |
|
472 | should_allow_api_authentication(:post, | |
|
473 | '/issues.json', | |
|
474 | {:issue => {:project_id => 1, :subject => 'API test', | |
|
475 | :tracker_id => 2, :status_id => 3}}, | |
|
476 | {:success_code => :created}) | |
|
477 | 408 | |
|
478 |
|
|
|
409 | test "POST /issues.json should create an issue with the attributes" do | |
|
479 | 410 |
|
|
480 | 411 |
|
|
481 | 412 |
|
@@ -490,10 +421,7 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
490 | 421 |
|
|
491 | 422 |
|
|
492 | 423 | |
|
493 | end | |
|
494 | ||
|
495 | context "POST /issues.json with failure" do | |
|
496 | should "have an errors element" do | |
|
424 | test "POST /issues.json with failure should return errors" do | |
|
497 | 425 |
|
|
498 | 426 |
|
|
499 | 427 |
|
@@ -501,204 +429,109 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base | |||
|
501 | 429 |
|
|
502 | 430 |
|
|
503 | 431 |
|
|
504 | end | |
|
505 | ||
|
506 | # Issue 6 is on a private project | |
|
507 | context "PUT /issues/6.xml" do | |
|
508 | setup do | |
|
509 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} | |
|
510 | end | |
|
511 | ||
|
512 | should_allow_api_authentication(:put, | |
|
513 | '/issues/6.xml', | |
|
514 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
|
515 | {:success_code => :ok}) | |
|
516 | ||
|
517 | should "not create a new issue" do | |
|
518 | assert_no_difference('Issue.count') do | |
|
519 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
520 | end | |
|
521 | end | |
|
522 | 432 | |
|
523 | should "create a new journal" do | |
|
433 | test "PUT /issues/:id.xml" do | |
|
524 | 434 |
|
|
525 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
526 | end | |
|
527 | end | |
|
528 | ||
|
529 | should "add the note to the journal" do | |
|
530 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
531 | ||
|
532 | journal = Journal.last | |
|
533 | assert_equal "A new note", journal.notes | |
|
435 | put '/issues/6.xml', | |
|
436 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
|
437 | credentials('jsmith') | |
|
534 | 438 | end |
|
535 | 439 | |
|
536 | should "update the issue" do | |
|
537 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
538 | ||
|
539 | 440 |
|
|
540 | 441 |
|
|
442 | journal = Journal.last | |
|
443 | assert_equal "A new note", journal.notes | |
|
541 | 444 |
|
|
542 | 445 | |
|
543 | end | |
|
544 | ||
|
545 | context "PUT /issues/3.xml with custom fields" do | |
|
546 | setup do | |
|
547 | @parameters = { | |
|
548 | :issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, | |
|
549 | {'id' => '2', 'value' => '150'}]} | |
|
550 | } | |
|
551 | end | |
|
552 | ||
|
553 | should "update custom fields" do | |
|
554 | assert_no_difference('Issue.count') do | |
|
555 | put '/issues/3.xml', @parameters, credentials('jsmith') | |
|
556 | end | |
|
446 | test "PUT /issues/:id.xml with custom fields" do | |
|
447 | put '/issues/3.xml', | |
|
448 | {:issue => {:custom_fields => [ | |
|
449 | {'id' => '1', 'value' => 'PostgreSQL' }, | |
|
450 | {'id' => '2', 'value' => '150'} | |
|
451 | ]}}, | |
|
452 | credentials('jsmith') | |
|
557 | 453 | |
|
558 | 454 |
|
|
559 | 455 |
|
|
560 | 456 |
|
|
561 | 457 |
|
|
562 | end | |
|
563 | 458 | |
|
564 |
|
|
|
565 | setup do | |
|
459 | test "PUT /issues/:id.xml with multi custom fields" do | |
|
566 | 460 |
|
|
567 | 461 |
|
|
568 | @parameters = { | |
|
569 | :issue => {:custom_fields => [{'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] }, | |
|
570 | {'id' => '2', 'value' => '150'}]} | |
|
571 | } | |
|
572 | end | |
|
573 | 462 | |
|
574 | should "update custom fields" do | |
|
575 | assert_no_difference('Issue.count') do | |
|
576 | put '/issues/3.xml', @parameters, credentials('jsmith') | |
|
577 | end | |
|
463 | put '/issues/3.xml', | |
|
464 | {:issue => {:custom_fields => [ | |
|
465 | {'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] }, | |
|
466 | {'id' => '2', 'value' => '150'} | |
|
467 | ]}}, | |
|
468 | credentials('jsmith') | |
|
578 | 469 | |
|
579 | 470 |
|
|
580 | 471 |
|
|
581 | 472 |
|
|
582 | 473 |
|
|
583 | end | |
|
584 | 474 | |
|
585 |
|
|
|
586 | setup do | |
|
587 |
|
|
|
588 | end | |
|
589 | ||
|
590 | should "update project" do | |
|
591 | assert_no_difference('Issue.count') do | |
|
592 | put '/issues/3.xml', @parameters, credentials('jsmith') | |
|
593 | end | |
|
475 | test "PUT /issues/:id.xml with project change" do | |
|
476 | put '/issues/3.xml', | |
|
477 | {:issue => {:project_id => 2, :subject => 'Project changed'}}, | |
|
478 | credentials('jsmith') | |
|
594 | 479 | |
|
595 | 480 |
|
|
596 | 481 |
|
|
597 | 482 |
|
|
598 | 483 |
|
|
599 | end | |
|
600 | ||
|
601 | context "PUT /issues/6.xml with failed update" do | |
|
602 | setup do | |
|
603 | @parameters = {:issue => {:subject => ''}} | |
|
604 | end | |
|
605 | ||
|
606 | should "not create a new issue" do | |
|
607 | assert_no_difference('Issue.count') do | |
|
608 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
609 | end | |
|
610 | end | |
|
611 | 484 | |
|
612 | should "not create a new journal" do | |
|
613 | assert_no_difference('Journal.count') do | |
|
614 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
615 | end | |
|
616 | end | |
|
617 | ||
|
618 | should "have an errors tag" do | |
|
619 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
|
485 | test "PUT /issues/:id.xml with failed update" do | |
|
486 | put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith') | |
|
620 | 487 | |
|
488 | assert_response :unprocessable_entity | |
|
621 | 489 |
|
|
622 | 490 |
|
|
623 | end | |
|
624 | ||
|
625 | context "PUT /issues/6.json" do | |
|
626 | setup do | |
|
627 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} | |
|
628 | end | |
|
629 | ||
|
630 | should_allow_api_authentication(:put, | |
|
631 | '/issues/6.json', | |
|
632 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
|
633 | {:success_code => :ok}) | |
|
634 | 491 | |
|
635 | should "update the issue" do | |
|
636 | assert_no_difference('Issue.count') do | |
|
492 | test "PUT /issues/:id.json" do | |
|
637 | 493 |
|
|
638 | put '/issues/6.json', @parameters, credentials('jsmith') | |
|
494 | put '/issues/6.json', | |
|
495 | {:issue => {:subject => 'API update', :notes => 'A new note'}}, | |
|
496 | credentials('jsmith') | |
|
639 | 497 | |
|
640 | 498 |
|
|
641 | 499 |
|
|
642 | 500 |
|
|
643 | end | |
|
644 | 501 | |
|
645 | 502 |
|
|
646 | 503 |
|
|
647 | 504 |
|
|
648 | 505 |
|
|
649 | 506 |
|
|
650 | end | |
|
651 | 507 | |
|
652 |
|
|
|
653 | should "return errors" do | |
|
654 | assert_no_difference('Issue.count') do | |
|
655 | assert_no_difference('Journal.count') do | |
|
508 | test "PUT /issues/:id.json with failed update" do | |
|
656 | 509 |
|
|
657 | 510 | |
|
658 | 511 |
|
|
659 | end | |
|
660 | end | |
|
661 | ||
|
662 | 512 |
|
|
663 | 513 |
|
|
664 | 514 |
|
|
665 | end | |
|
666 | ||
|
667 | context "DELETE /issues/1.xml" do | |
|
668 | should_allow_api_authentication(:delete, | |
|
669 | '/issues/6.xml', | |
|
670 | {}, | |
|
671 | {:success_code => :ok}) | |
|
672 | 515 | |
|
673 | should "delete the issue" do | |
|
516 | test "DELETE /issues/:id.xml" do | |
|
674 | 517 |
|
|
675 | 518 |
|
|
676 | 519 | |
|
677 | 520 |
|
|
678 | 521 |
|
|
679 | 522 |
|
|
680 | ||
|
681 | 523 |
|
|
682 | 524 |
|
|
683 | end | |
|
684 | 525 | |
|
685 |
|
|
|
686 | should_allow_api_authentication(:delete, | |
|
687 | '/issues/6.json', | |
|
688 | {}, | |
|
689 | {:success_code => :ok}) | |
|
690 | ||
|
691 | should "delete the issue" do | |
|
526 | test "DELETE /issues/:id.json" do | |
|
692 | 527 |
|
|
693 | 528 |
|
|
694 | 529 | |
|
695 | 530 |
|
|
696 | 531 |
|
|
697 | 532 |
|
|
698 | ||
|
699 | 533 |
|
|
700 | 534 |
|
|
701 | end | |
|
702 | 535 | |
|
703 | 536 | test "POST /issues/:id/watchers.xml should add watcher" do |
|
704 | 537 | assert_difference 'Watcher.count' do |
@@ -601,98 +601,63 class UserTest < ActiveSupport::TestCase | |||
|
601 | 601 | end |
|
602 | 602 | |
|
603 | 603 | if ldap_configured? |
|
604 |
|
|
|
605 | context "with failed connection to the LDAP server" do | |
|
606 | should "return nil" do | |
|
607 | @auth_source = AuthSourceLdap.find(1) | |
|
604 | test "#try_to_login using LDAP with failed connection to the LDAP server" do | |
|
605 | auth_source = AuthSourceLdap.find(1) | |
|
608 | 606 |
|
|
609 | 607 | |
|
610 | 608 |
|
|
611 | 609 |
|
|
612 | end | |
|
613 | 610 | |
|
614 | context "with an unsuccessful authentication" do | |
|
615 | should "return nil" do | |
|
611 | test "#try_to_login using LDAP" do | |
|
616 | 612 |
|
|
617 | 613 |
|
|
618 | end | |
|
619 | 614 | |
|
620 |
|
|
|
621 | setup do | |
|
622 | @auth_source = AuthSourceLdap.find(1) | |
|
623 | @auth_source.account = "uid=$login,ou=Person,dc=redmine,dc=org" | |
|
624 | @auth_source.account_password = '' | |
|
625 | @auth_source.save! | |
|
615 | test "#try_to_login using LDAP binding with user's account" do | |
|
616 | auth_source = AuthSourceLdap.find(1) | |
|
617 | auth_source.account = "uid=$login,ou=Person,dc=redmine,dc=org" | |
|
618 | auth_source.account_password = '' | |
|
619 | auth_source.save! | |
|
626 | 620 | |
|
627 |
|
|
|
628 |
|
|
|
629 |
|
|
|
630 | end | |
|
621 | ldap_user = User.new(:mail => 'example1@redmine.org', :firstname => 'LDAP', :lastname => 'user', :auth_source_id => 1) | |
|
622 | ldap_user.login = 'example1' | |
|
623 | ldap_user.save! | |
|
631 | 624 | |
|
632 | context "with a successful authentication" do | |
|
633 | should "return the user" do | |
|
634 | 625 |
|
|
635 | end | |
|
636 | end | |
|
637 | ||
|
638 | context "with an unsuccessful authentication" do | |
|
639 | should "return nil" do | |
|
640 | 626 |
|
|
641 | 627 |
|
|
642 | end | |
|
643 | end | |
|
644 | 628 | |
|
645 |
|
|
|
646 | setup do | |
|
647 | @auth_source = AuthSourceLdap.find(1) | |
|
648 | @auth_source.update_attribute :onthefly_register, true | |
|
649 | end | |
|
629 | test "#try_to_login using LDAP on the fly registration" do | |
|
630 | AuthSourceLdap.find(1).update_attribute :onthefly_register, true | |
|
650 | 631 | |
|
651 | context "with a successful authentication" do | |
|
652 | should "create a new user account if it doesn't exist" do | |
|
653 | 632 |
|
|
654 |
|
|
|
655 | assert !user.admin? | |
|
633 | assert User.try_to_login('edavis', '123456') | |
|
656 | 634 |
|
|
657 | end | |
|
658 | ||
|
659 | should "retrieve existing user" do | |
|
660 | user = User.try_to_login('edavis', '123456') | |
|
661 | user.admin = true | |
|
662 | user.save! | |
|
663 | 635 | |
|
664 | 636 |
|
|
665 |
|
|
|
666 | assert user.admin? | |
|
667 | end | |
|
668 | end | |
|
637 | assert User.try_to_login('edavis', '123456') | |
|
669 | 638 |
|
|
670 | 639 | |
|
671 | context "binding with user's account" do | |
|
672 | setup do | |
|
673 | @auth_source = AuthSourceLdap.find(1) | |
|
674 | @auth_source.account = "uid=$login,ou=Person,dc=redmine,dc=org" | |
|
675 | @auth_source.account_password = '' | |
|
676 | @auth_source.save! | |
|
640 | assert_nil User.try_to_login('example1', '11111') | |
|
677 | 641 |
|
|
678 | 642 | |
|
679 | context "with a successful authentication" do | |
|
680 | should "create a new user account if it doesn't exist" do | |
|
643 | test "#try_to_login using LDAP on the fly registration and binding with user's account" do | |
|
644 | auth_source = AuthSourceLdap.find(1) | |
|
645 | auth_source.update_attribute :onthefly_register, true | |
|
646 | auth_source = AuthSourceLdap.find(1) | |
|
647 | auth_source.account = "uid=$login,ou=Person,dc=redmine,dc=org" | |
|
648 | auth_source.account_password = '' | |
|
649 | auth_source.save! | |
|
650 | ||
|
681 | 651 |
|
|
682 |
|
|
|
683 | assert_kind_of User, user | |
|
684 | end | |
|
652 | assert User.try_to_login('example1', '123456') | |
|
685 | 653 |
|
|
654 | ||
|
655 | assert_no_difference('User.count') do | |
|
656 | assert User.try_to_login('edavis', '123456') | |
|
686 | 657 |
|
|
687 | 658 | |
|
688 | context "with an unsuccessful authentication" do | |
|
689 | should "return nil" do | |
|
690 | 659 |
|
|
691 | 660 |
|
|
692 | end | |
|
693 | end | |
|
694 | end | |
|
695 | end | |
|
696 | 661 | |
|
697 | 662 | else |
|
698 | 663 | puts "Skipping LDAP tests." |
General Comments 0
You need to be logged in to leave comments.
Login now