##// END OF EJS Templates
Removed some test contexts....
Jean-Philippe Lang -
r13264:4989c9f6a845
parent child
Show More
@@ -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 should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.xml")
48 end
49
50 context "in :json format" do
51 42 should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.json")
52 43 end
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 should_allow_http_basic_auth_with_key(:get, "/news.xml")
44 end
45
46 context "in :json format" do
47 40 should_allow_http_basic_auth_with_key(:get, "/news.json")
48 41 end
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 # Use a private project to make sure auth is really working and not just
53 52 # only showing public issues.
54 53 should_allow_api_authentication(:get, "/projects/private-child/issues.xml")
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 end
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 get '/issues.xml?nometa=1'
75
76 97 assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])'
77 98 end
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 get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'}
83
84 102 assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])'
85 103 end
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 end
87 112
88 context "with relations" do
89 should "display relations" do
113 test "GET /issues.xml with relations" do
90 114 get '/issues.xml?include=relations'
91 115
92 116 assert_response :success
@@ -102,46 +126,41 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
102 126 assert_select '~ relations relation', 0
103 127 end
104 128 end
105 end
106 129
107 context "with invalid query params" do
108 should "return errors" do
130 test "GET /issues.xml with invalid query params" do
109 131 get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}}
110 132
111 133 assert_response :unprocessable_entity
112 134 assert_equal 'application/xml', @response.content_type
113 135 assert_select 'errors error', :text => "Start date can't be blank"
114 136 end
115 end
116 137
117 context "with custom field filter" do
118 should "show only issues with the custom field value" do
138 test "GET /issues.xml with custom field filter" do
119 139 get '/issues.xml',
120 {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='},
121 :v => {:cf_1 => ['MySQL']}}
140 {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}}
141
122 142 expected_ids = Issue.visible.
123 143 joins(:custom_values).
124 144 where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id)
145 assert expected_ids.any?
146
125 147 assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
126 148 ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
127 149 end
128 150 end
129 end
130 151
131 context "with custom field filter (shorthand method)" do
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 get '/issues.xml', { :cf_1 => 'MySQL' }
134 154
135 155 expected_ids = Issue.visible.
136 156 joins(:custom_values).
137 157 where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id)
158 assert expected_ids.any?
138 159
139 160 assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
140 161 ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
141 162 end
142 163 end
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 get '/issues.xml?status_id=5'
181 195
182 196 expected_ids = Issue.visible.where(:status_id => 5).map(&:id)
197 assert expected_ids.any?
183 198
184 199 assert_select 'issues > issue > id', :count => expected_ids.count do |ids|
185 200 ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) }
186 201 end
187 202 end
188 end
189 203
190 context "/index.json with filter" do
191 should "show only issues with the status_id" do
204 test "GET /issues.json with filter" do
192 205 get '/issues.json?status_id=5'
193 206
194 207 json = ActiveSupport::JSON.decode(response.body)
@@ -197,21 +210,7 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
197 210 assert status_ids_used.all? {|id| id == 5 }
198 211 end
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 get '/issues/1.xml?include=journals'
216 215
217 216 assert_select 'issue journals[type=array]' do
@@ -225,12 +224,8 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
225 224 end
226 225 end
227 226 end
228 end
229 end
230 227
231 context "with custom fields" do
232 context ".xml" do
233 should "display custom fields" do
228 test "GET /issues/:id.xml with custom fields" do
234 229 get '/issues/3.xml'
235 230
236 231 assert_select 'issue custom_fields[type=array]' do
@@ -238,25 +233,18 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
238 233 assert_select 'value', :text => 'MySQL'
239 234 end
240 235 end
241
242 236 assert_nothing_raised do
243 237 Hash.from_xml(response.body).to_xml
244 238 end
245 239 end
246 end
247 end
248 240
249 context "with multi custom fields" do
250 setup do
241 test "GET /issues/:id.xml with multi custom fields" do
251 242 field = CustomField.find(1)
252 243 field.update_attribute :multiple, true
253 244 issue = Issue.find(3)
254 245 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
255 246 issue.save!
256 end
257 247
258 context ".xml" do
259 should "display custom fields" do
260 248 get '/issues/3.xml'
261 249 assert_response :success
262 250
@@ -265,7 +253,6 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
265 253 assert_select 'value[type=array] value', 2
266 254 end
267 255 end
268
269 256 xml = Hash.from_xml(response.body)
270 257 custom_fields = xml['issue']['custom_fields']
271 258 assert_kind_of Array, custom_fields
@@ -273,12 +260,17 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
273 260 assert_kind_of Hash, field
274 261 assert_equal ['MySQL', 'Oracle'], field['value'].sort
275 262 end
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 get '/issues/3.json'
281 272 assert_response :success
273
282 274 json = ActiveSupport::JSON.decode(response.body)
283 275 custom_fields = json['issue']['custom_fields']
284 276 assert_kind_of Array, custom_fields
@@ -286,20 +278,14 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
286 278 assert_kind_of Hash, field
287 279 assert_equal ['MySQL', 'Oracle'], field['value'].sort
288 280 end
289 end
290 end
291 281
292 context "with empty value for multi custom field" do
293 setup do
282 test "GET /issues/:id.xml with empty value for multi custom field" do
294 283 field = CustomField.find(1)
295 284 field.update_attribute :multiple, true
296 285 issue = Issue.find(3)
297 286 issue.custom_field_values = {1 => ['']}
298 287 issue.save!
299 end
300 288
301 context ".xml" do
302 should "display custom fields" do
303 289 get '/issues/3.xml'
304 290
305 291 assert_select 'issue custom_fields[type=array]' do
@@ -307,7 +293,6 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
307 293 assert_select 'value[type=array]:empty'
308 294 end
309 295 end
310
311 296 xml = Hash.from_xml(response.body)
312 297 custom_fields = xml['issue']['custom_fields']
313 298 assert_kind_of Array, custom_fields
@@ -315,10 +300,14 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
315 300 assert_kind_of Hash, field
316 301 assert_equal [], field['value']
317 302 end
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 get '/issues/3.json'
323 312 assert_response :success
324 313 json = ActiveSupport::JSON.decode(response.body)
@@ -328,12 +317,8 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
328 317 assert_kind_of Hash, field
329 318 assert_equal [], field['value'].sort
330 319 end
331 end
332 end
333 320
334 context "with attachments" do
335 context ".xml" do
336 should "display attachments" do
321 test "GET /issues/:id.xml with attachments" do
337 322 get '/issues/3.xml?include=attachments'
338 323
339 324 assert_select 'issue attachments[type=array]' do
@@ -344,61 +329,24 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
344 329 end
345 330 end
346 331 end
347 end
348 end
349 332
350 context "with subtasks" do
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 assert_select 'issue children[type=array]' do
374 338 assert_select 'issue', 2
375 assert_select 'issue[id=?]', @c1.id.to_s do
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 end
382 341 end
383 342
384 context ".json" do
385 should "display children" do
386 get '/issues/1.json?include=children'
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 json = ActiveSupport::JSON.decode(response.body)
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 assert_difference('Issue.count') do
433 374 post '/issues.xml',
434 375 {:issue => {:project_id => 1, :subject => 'API test',
@@ -444,7 +385,6 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
444 385 assert_equal 'application/xml', @response.content_type
445 386 assert_select 'issue > id', :text => issue.id.to_s
446 387 end
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 context "POST /issues.xml with failure" do
462 should "have an errors tag" do
401 test "POST /issues.xml with failure should return errors" do
463 402 assert_no_difference('Issue.count') do
464 403 post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith')
465 404 end
466 405
467 406 assert_select 'errors error', :text => "Subject can't be blank"
468 407 end
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 should "create an issue with the attributes" do
409 test "POST /issues.json should create an issue with the attributes" do
479 410 assert_difference('Issue.count') do
480 411 post '/issues.json',
481 412 {:issue => {:project_id => 1, :subject => 'API test',
@@ -490,10 +421,7 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
490 421 assert_equal 'API test', issue.subject
491 422 end
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 assert_no_difference('Issue.count') do
498 426 post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith')
499 427 end
@@ -501,204 +429,109 class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
501 429 json = ActiveSupport::JSON.decode(response.body)
502 430 assert json['errors'].include?("Subject can't be blank")
503 431 end
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 assert_difference('Journal.count') do
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 issue = Issue.find(6)
540 441 assert_equal "API update", issue.subject
442 journal = Journal.last
443 assert_equal "A new note", journal.notes
541 444 end
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 issue = Issue.find(3)
559 455 assert_equal '150', issue.custom_value_for(2).value
560 456 assert_equal 'PostgreSQL', issue.custom_value_for(1).value
561 457 end
562 end
563 458
564 context "PUT /issues/3.xml with multi custom fields" do
565 setup do
459 test "PUT /issues/:id.xml with multi custom fields" do
566 460 field = CustomField.find(1)
567 461 field.update_attribute :multiple, true
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 issue = Issue.find(3)
580 471 assert_equal '150', issue.custom_value_for(2).value
581 472 assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1).sort
582 473 end
583 end
584 474
585 context "PUT /issues/3.xml with project change" do
586 setup do
587 @parameters = {:issue => {:project_id => 2, :subject => 'Project changed'}}
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 issue = Issue.find(3)
596 481 assert_equal 2, issue.project_id
597 482 assert_equal 'Project changed', issue.subject
598 483 end
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 assert_select 'errors error', :text => "Subject can't be blank"
622 490 end
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 assert_difference('Journal.count') do
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 assert_response :ok
641 499 assert_equal '', response.body
642 500 end
643 end
644 501
645 502 issue = Issue.find(6)
646 503 assert_equal "API update", issue.subject
647 504 journal = Journal.last
648 505 assert_equal "A new note", journal.notes
649 506 end
650 end
651 507
652 context "PUT /issues/6.json with failed update" do
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 put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith')
657 510
658 511 assert_response :unprocessable_entity
659 end
660 end
661
662 512 json = ActiveSupport::JSON.decode(response.body)
663 513 assert json['errors'].include?("Subject can't be blank")
664 514 end
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 assert_difference('Issue.count', -1) do
675 518 delete '/issues/6.xml', {}, credentials('jsmith')
676 519
677 520 assert_response :ok
678 521 assert_equal '', response.body
679 522 end
680
681 523 assert_nil Issue.find_by_id(6)
682 524 end
683 end
684 525
685 context "DELETE /issues/1.json" do
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 assert_difference('Issue.count', -1) do
693 528 delete '/issues/6.json', {}, credentials('jsmith')
694 529
695 530 assert_response :ok
696 531 assert_equal '', response.body
697 532 end
698
699 533 assert_nil Issue.find_by_id(6)
700 534 end
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 context "#try_to_login using LDAP" do
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 AuthSource.any_instance.stubs(:initialize_ldap_con).raises(Net::LDAP::LdapError, 'Cannot connect')
609 607
610 608 assert_equal nil, User.try_to_login('edavis', 'wrong')
611 609 end
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 assert_equal nil, User.try_to_login('edavis', 'wrong')
617 613 end
618 end
619 614
620 context "binding with user's account" do
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 @ldap_user = User.new(:mail => 'example1@redmine.org', :firstname => 'LDAP', :lastname => 'user', :auth_source_id => 1)
628 @ldap_user.login = 'example1'
629 @ldap_user.save!
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 assert_equal @ldap_user, User.try_to_login('example1', '123456')
635 end
636 end
637
638 context "with an unsuccessful authentication" do
639 should "return nil" do
640 626 assert_nil User.try_to_login('example1', '11111')
641 627 end
642 end
643 end
644 628
645 context "on the fly registration" do
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 assert_difference('User.count') do
654 user = User.try_to_login('edavis', '123456')
655 assert !user.admin?
633 assert User.try_to_login('edavis', '123456')
656 634 end
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 assert_no_difference('User.count') do
665 user = User.try_to_login('edavis', '123456')
666 assert user.admin?
667 end
668 end
637 assert User.try_to_login('edavis', '123456')
669 638 end
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 end
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 assert_difference('User.count') do
682 user = User.try_to_login('example1', '123456')
683 assert_kind_of User, user
684 end
652 assert User.try_to_login('example1', '123456')
685 653 end
654
655 assert_no_difference('User.count') do
656 assert User.try_to_login('edavis', '123456')
686 657 end
687 658
688 context "with an unsuccessful authentication" do
689 should "return nil" do
690 659 assert_nil User.try_to_login('example1', '11111')
691 660 end
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