@@ -40,7 +40,7 class ApiTest::AttachmentsTest < ActionController::IntegrationTest | |||||
40 | context "/attachments/:id" do |
|
40 | context "/attachments/:id" do | |
41 | context "GET" do |
|
41 | context "GET" do | |
42 | should "return the attachment" do |
|
42 | should "return the attachment" do | |
43 |
get '/attachments/7.xml', {}, |
|
43 | get '/attachments/7.xml', {}, credentials('jsmith') | |
44 | assert_response :success |
|
44 | assert_response :success | |
45 | assert_equal 'application/xml', @response.content_type |
|
45 | assert_equal 'application/xml', @response.content_type | |
46 | assert_tag :tag => 'attachment', |
|
46 | assert_tag :tag => 'attachment', | |
@@ -69,8 +69,7 class ApiTest::AttachmentsTest < ActionController::IntegrationTest | |||||
69 | context "/attachments/download/:id/:filename" do |
|
69 | context "/attachments/download/:id/:filename" do | |
70 | context "GET" do |
|
70 | context "GET" do | |
71 | should "return the attachment content" do |
|
71 | should "return the attachment content" do | |
72 | get '/attachments/download/7/archive.zip', |
|
72 | get '/attachments/download/7/archive.zip', {}, credentials('jsmith') | |
73 | {}, :authorization => credentials('jsmith') |
|
|||
74 | assert_response :success |
|
73 | assert_response :success | |
75 | assert_equal 'application/octet-stream', @response.content_type |
|
74 | assert_equal 'application/octet-stream', @response.content_type | |
76 | set_tmp_attachments_directory |
|
75 | set_tmp_attachments_directory |
@@ -41,7 +41,7 class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest | |||||
41 | context "with a valid HTTP authentication" do |
|
41 | context "with a valid HTTP authentication" do | |
42 | setup do |
|
42 | setup do | |
43 | @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password') |
|
43 | @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password') | |
44 |
get "/news.xml", nil, |
|
44 | get "/news.xml", nil, credentials(@user.login, 'my_password') | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | should_respond_with :unauthorized |
|
47 | should_respond_with :unauthorized | |
@@ -55,7 +55,7 class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest | |||||
55 | setup do |
|
55 | setup do | |
56 | @user = User.generate_with_protected! |
|
56 | @user = User.generate_with_protected! | |
57 | @token = Token.generate!(:user => @user, :action => 'api') |
|
57 | @token = Token.generate!(:user => @user, :action => 'api') | |
58 |
get "/news.xml", nil, |
|
58 | get "/news.xml", nil, credentials(@token.value, 'X') | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | should_respond_with :unauthorized |
|
61 | should_respond_with :unauthorized | |
@@ -84,7 +84,7 class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest | |||||
84 | context "with a valid HTTP authentication" do |
|
84 | context "with a valid HTTP authentication" do | |
85 | setup do |
|
85 | setup do | |
86 | @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password') |
|
86 | @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password') | |
87 |
get "/news.json", nil, |
|
87 | get "/news.json", nil, credentials(@user.login, 'my_password') | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | should_respond_with :unauthorized |
|
90 | should_respond_with :unauthorized | |
@@ -98,7 +98,7 class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest | |||||
98 | setup do |
|
98 | setup do | |
99 | @user = User.generate_with_protected! |
|
99 | @user = User.generate_with_protected! | |
100 | @token = Token.generate!(:user => @user, :action => 'api') |
|
100 | @token = Token.generate!(:user => @user, :action => 'api') | |
101 |
get "/news.json", nil, |
|
101 | get "/news.json", nil, credentials(@token.value, 'DoesNotMatter') | |
102 | end |
|
102 | end | |
103 |
|
103 | |||
104 | should_respond_with :unauthorized |
|
104 | should_respond_with :unauthorized |
@@ -30,7 +30,7 class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest | |||||
30 |
|
30 | |||
31 | context "GET /projects/:project_id/issue_categories.xml" do |
|
31 | context "GET /projects/:project_id/issue_categories.xml" do | |
32 | should "return issue categories" do |
|
32 | should "return issue categories" do | |
33 |
get '/projects/1/issue_categories.xml', {}, |
|
33 | get '/projects/1/issue_categories.xml', {}, credentials('jsmith') | |
34 | assert_response :success |
|
34 | assert_response :success | |
35 | assert_equal 'application/xml', @response.content_type |
|
35 | assert_equal 'application/xml', @response.content_type | |
36 | assert_tag :tag => 'issue_categories', |
|
36 | assert_tag :tag => 'issue_categories', | |
@@ -40,7 +40,7 class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest | |||||
40 |
|
40 | |||
41 | context "GET /issue_categories/2.xml" do |
|
41 | context "GET /issue_categories/2.xml" do | |
42 | should "return requested issue category" do |
|
42 | should "return requested issue category" do | |
43 |
get '/issue_categories/2.xml', {}, |
|
43 | get '/issue_categories/2.xml', {}, credentials('jsmith') | |
44 | assert_response :success |
|
44 | assert_response :success | |
45 | assert_equal 'application/xml', @response.content_type |
|
45 | assert_equal 'application/xml', @response.content_type | |
46 | assert_tag :tag => 'issue_category', |
|
46 | assert_tag :tag => 'issue_category', | |
@@ -51,7 +51,7 class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest | |||||
51 | context "POST /projects/:project_id/issue_categories.xml" do |
|
51 | context "POST /projects/:project_id/issue_categories.xml" do | |
52 | should "return create issue category" do |
|
52 | should "return create issue category" do | |
53 | assert_difference 'IssueCategory.count' do |
|
53 | assert_difference 'IssueCategory.count' do | |
54 |
post '/projects/1/issue_categories.xml', {:issue_category => {:name => 'API'}}, |
|
54 | post '/projects/1/issue_categories.xml', {:issue_category => {:name => 'API'}}, credentials('jsmith') | |
55 | end |
|
55 | end | |
56 | assert_response :created |
|
56 | assert_response :created | |
57 | assert_equal 'application/xml', @response.content_type |
|
57 | assert_equal 'application/xml', @response.content_type | |
@@ -64,7 +64,7 class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest | |||||
64 | context "with invalid parameters" do |
|
64 | context "with invalid parameters" do | |
65 | should "return errors" do |
|
65 | should "return errors" do | |
66 | assert_no_difference 'IssueCategory.count' do |
|
66 | assert_no_difference 'IssueCategory.count' do | |
67 |
post '/projects/1/issue_categories.xml', {:issue_category => {:name => ''}}, |
|
67 | post '/projects/1/issue_categories.xml', {:issue_category => {:name => ''}}, credentials('jsmith') | |
68 | end |
|
68 | end | |
69 | assert_response :unprocessable_entity |
|
69 | assert_response :unprocessable_entity | |
70 | assert_equal 'application/xml', @response.content_type |
|
70 | assert_equal 'application/xml', @response.content_type | |
@@ -78,7 +78,7 class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest | |||||
78 | context "with valid parameters" do |
|
78 | context "with valid parameters" do | |
79 | should "update issue category" do |
|
79 | should "update issue category" do | |
80 | assert_no_difference 'IssueCategory.count' do |
|
80 | assert_no_difference 'IssueCategory.count' do | |
81 |
put '/issue_categories/2.xml', {:issue_category => {:name => 'API Update'}}, |
|
81 | put '/issue_categories/2.xml', {:issue_category => {:name => 'API Update'}}, credentials('jsmith') | |
82 | end |
|
82 | end | |
83 | assert_response :ok |
|
83 | assert_response :ok | |
84 | assert_equal 'API Update', IssueCategory.find(2).name |
|
84 | assert_equal 'API Update', IssueCategory.find(2).name | |
@@ -88,7 +88,7 class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest | |||||
88 | context "with invalid parameters" do |
|
88 | context "with invalid parameters" do | |
89 | should "return errors" do |
|
89 | should "return errors" do | |
90 | assert_no_difference 'IssueCategory.count' do |
|
90 | assert_no_difference 'IssueCategory.count' do | |
91 |
put '/issue_categories/2.xml', {:issue_category => {:name => ''}}, |
|
91 | put '/issue_categories/2.xml', {:issue_category => {:name => ''}}, credentials('jsmith') | |
92 | end |
|
92 | end | |
93 | assert_response :unprocessable_entity |
|
93 | assert_response :unprocessable_entity | |
94 | assert_equal 'application/xml', @response.content_type |
|
94 | assert_equal 'application/xml', @response.content_type | |
@@ -101,7 +101,7 class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest | |||||
101 | context "DELETE /issue_categories/1.xml" do |
|
101 | context "DELETE /issue_categories/1.xml" do | |
102 | should "destroy issue categories" do |
|
102 | should "destroy issue categories" do | |
103 | assert_difference 'IssueCategory.count', -1 do |
|
103 | assert_difference 'IssueCategory.count', -1 do | |
104 |
delete '/issue_categories/1.xml', {}, |
|
104 | delete '/issue_categories/1.xml', {}, credentials('jsmith') | |
105 | end |
|
105 | end | |
106 | assert_response :ok |
|
106 | assert_response :ok | |
107 | assert_nil IssueCategory.find_by_id(1) |
|
107 | assert_nil IssueCategory.find_by_id(1) | |
@@ -113,7 +113,7 class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest | |||||
113 |
|
113 | |||
114 | assert_difference 'IssueCategory.count', -1 do |
|
114 | assert_difference 'IssueCategory.count', -1 do | |
115 | assert_difference 'Issue.count(:conditions => {:category_id => 2})', 3 do |
|
115 | assert_difference 'Issue.count(:conditions => {:category_id => 2})', 3 do | |
116 |
delete '/issue_categories/1.xml', {:reassign_to_id => 2}, |
|
116 | delete '/issue_categories/1.xml', {:reassign_to_id => 2}, credentials('jsmith') | |
117 | end |
|
117 | end | |
118 | end |
|
118 | end | |
119 | assert_response :ok |
|
119 | assert_response :ok |
@@ -35,7 +35,7 class ApiTest::IssueRelationsTest < ActionController::IntegrationTest | |||||
35 | context "/issues/:issue_id/relations" do |
|
35 | context "/issues/:issue_id/relations" do | |
36 | context "GET" do |
|
36 | context "GET" do | |
37 | should "return issue relations" do |
|
37 | should "return issue relations" do | |
38 |
get '/issues/9/relations.xml', {}, |
|
38 | get '/issues/9/relations.xml', {}, credentials('jsmith') | |
39 |
|
39 | |||
40 | assert_response :success |
|
40 | assert_response :success | |
41 | assert_equal 'application/xml', @response.content_type |
|
41 | assert_equal 'application/xml', @response.content_type | |
@@ -55,7 +55,7 class ApiTest::IssueRelationsTest < ActionController::IntegrationTest | |||||
55 | context "POST" do |
|
55 | context "POST" do | |
56 | should "create a relation" do |
|
56 | should "create a relation" do | |
57 | assert_difference('IssueRelation.count') do |
|
57 | assert_difference('IssueRelation.count') do | |
58 |
post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, |
|
58 | post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, credentials('jsmith') | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | relation = IssueRelation.first(:order => 'id DESC') |
|
61 | relation = IssueRelation.first(:order => 'id DESC') | |
@@ -71,7 +71,7 class ApiTest::IssueRelationsTest < ActionController::IntegrationTest | |||||
71 | context "with failure" do |
|
71 | context "with failure" do | |
72 | should "return the errors" do |
|
72 | should "return the errors" do | |
73 | assert_no_difference('IssueRelation.count') do |
|
73 | assert_no_difference('IssueRelation.count') do | |
74 |
post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, |
|
74 | post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, credentials('jsmith') | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | assert_response :unprocessable_entity |
|
77 | assert_response :unprocessable_entity | |
@@ -84,7 +84,7 class ApiTest::IssueRelationsTest < ActionController::IntegrationTest | |||||
84 | context "/relations/:id" do |
|
84 | context "/relations/:id" do | |
85 | context "GET" do |
|
85 | context "GET" do | |
86 | should "return the relation" do |
|
86 | should "return the relation" do | |
87 |
get '/relations/2.xml', {}, |
|
87 | get '/relations/2.xml', {}, credentials('jsmith') | |
88 |
|
88 | |||
89 | assert_response :success |
|
89 | assert_response :success | |
90 | assert_equal 'application/xml', @response.content_type |
|
90 | assert_equal 'application/xml', @response.content_type | |
@@ -95,7 +95,7 class ApiTest::IssueRelationsTest < ActionController::IntegrationTest | |||||
95 | context "DELETE" do |
|
95 | context "DELETE" do | |
96 | should "delete the relation" do |
|
96 | should "delete the relation" do | |
97 | assert_difference('IssueRelation.count', -1) do |
|
97 | assert_difference('IssueRelation.count', -1) do | |
98 |
delete '/relations/2.xml', {}, |
|
98 | delete '/relations/2.xml', {}, credentials('jsmith') | |
99 | end |
|
99 | end | |
100 |
|
100 | |||
101 | assert_response :ok |
|
101 | assert_response :ok |
@@ -344,7 +344,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
344 |
|
344 | |||
345 | should "create an issue with the attributes" do |
|
345 | should "create an issue with the attributes" do | |
346 | assert_difference('Issue.count') do |
|
346 | assert_difference('Issue.count') do | |
347 |
post '/issues.xml', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, |
|
347 | post '/issues.xml', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, credentials('jsmith') | |
348 | end |
|
348 | end | |
349 |
|
349 | |||
350 | issue = Issue.first(:order => 'id DESC') |
|
350 | issue = Issue.first(:order => 'id DESC') | |
@@ -362,7 +362,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
362 | context "POST /issues.xml with failure" do |
|
362 | context "POST /issues.xml with failure" do | |
363 | should "have an errors tag" do |
|
363 | should "have an errors tag" do | |
364 | assert_no_difference('Issue.count') do |
|
364 | assert_no_difference('Issue.count') do | |
365 |
post '/issues.xml', {:issue => {:project_id => 1}}, |
|
365 | post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith') | |
366 | end |
|
366 | end | |
367 |
|
367 | |||
368 | assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} |
|
368 | assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} | |
@@ -377,7 +377,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
377 |
|
377 | |||
378 | should "create an issue with the attributes" do |
|
378 | should "create an issue with the attributes" do | |
379 | assert_difference('Issue.count') do |
|
379 | assert_difference('Issue.count') do | |
380 |
post '/issues.json', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, |
|
380 | post '/issues.json', {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, credentials('jsmith') | |
381 | end |
|
381 | end | |
382 |
|
382 | |||
383 | issue = Issue.first(:order => 'id DESC') |
|
383 | issue = Issue.first(:order => 'id DESC') | |
@@ -392,7 +392,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
392 | context "POST /issues.json with failure" do |
|
392 | context "POST /issues.json with failure" do | |
393 | should "have an errors element" do |
|
393 | should "have an errors element" do | |
394 | assert_no_difference('Issue.count') do |
|
394 | assert_no_difference('Issue.count') do | |
395 |
post '/issues.json', {:issue => {:project_id => 1}}, |
|
395 | post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith') | |
396 | end |
|
396 | end | |
397 |
|
397 | |||
398 | json = ActiveSupport::JSON.decode(response.body) |
|
398 | json = ActiveSupport::JSON.decode(response.body) | |
@@ -404,7 +404,6 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
404 | context "PUT /issues/6.xml" do |
|
404 | context "PUT /issues/6.xml" do | |
405 | setup do |
|
405 | setup do | |
406 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} |
|
406 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} | |
407 | @headers = { :authorization => credentials('jsmith') } |
|
|||
408 | end |
|
407 | end | |
409 |
|
408 | |||
410 | should_allow_api_authentication(:put, |
|
409 | should_allow_api_authentication(:put, | |
@@ -414,25 +413,25 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
414 |
|
413 | |||
415 | should "not create a new issue" do |
|
414 | should "not create a new issue" do | |
416 | assert_no_difference('Issue.count') do |
|
415 | assert_no_difference('Issue.count') do | |
417 |
put '/issues/6.xml', @parameters, |
|
416 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
418 | end |
|
417 | end | |
419 | end |
|
418 | end | |
420 |
|
419 | |||
421 | should "create a new journal" do |
|
420 | should "create a new journal" do | |
422 | assert_difference('Journal.count') do |
|
421 | assert_difference('Journal.count') do | |
423 |
put '/issues/6.xml', @parameters, |
|
422 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
424 | end |
|
423 | end | |
425 | end |
|
424 | end | |
426 |
|
425 | |||
427 | should "add the note to the journal" do |
|
426 | should "add the note to the journal" do | |
428 |
put '/issues/6.xml', @parameters, |
|
427 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
429 |
|
428 | |||
430 | journal = Journal.last |
|
429 | journal = Journal.last | |
431 | assert_equal "A new note", journal.notes |
|
430 | assert_equal "A new note", journal.notes | |
432 | end |
|
431 | end | |
433 |
|
432 | |||
434 | should "update the issue" do |
|
433 | should "update the issue" do | |
435 |
put '/issues/6.xml', @parameters, |
|
434 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
436 |
|
435 | |||
437 | issue = Issue.find(6) |
|
436 | issue = Issue.find(6) | |
438 | assert_equal "API update", issue.subject |
|
437 | assert_equal "API update", issue.subject | |
@@ -443,12 +442,11 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
443 | context "PUT /issues/3.xml with custom fields" do |
|
442 | context "PUT /issues/3.xml with custom fields" do | |
444 | setup do |
|
443 | setup do | |
445 | @parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, {'id' => '2', 'value' => '150'}]}} |
|
444 | @parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, {'id' => '2', 'value' => '150'}]}} | |
446 | @headers = { :authorization => credentials('jsmith') } |
|
|||
447 | end |
|
445 | end | |
448 |
|
446 | |||
449 | should "update custom fields" do |
|
447 | should "update custom fields" do | |
450 | assert_no_difference('Issue.count') do |
|
448 | assert_no_difference('Issue.count') do | |
451 |
put '/issues/3.xml', @parameters, |
|
449 | put '/issues/3.xml', @parameters, credentials('jsmith') | |
452 | end |
|
450 | end | |
453 |
|
451 | |||
454 | issue = Issue.find(3) |
|
452 | issue = Issue.find(3) | |
@@ -460,23 +458,22 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
460 | context "PUT /issues/6.xml with failed update" do |
|
458 | context "PUT /issues/6.xml with failed update" do | |
461 | setup do |
|
459 | setup do | |
462 | @parameters = {:issue => {:subject => ''}} |
|
460 | @parameters = {:issue => {:subject => ''}} | |
463 | @headers = { :authorization => credentials('jsmith') } |
|
|||
464 | end |
|
461 | end | |
465 |
|
462 | |||
466 | should "not create a new issue" do |
|
463 | should "not create a new issue" do | |
467 | assert_no_difference('Issue.count') do |
|
464 | assert_no_difference('Issue.count') do | |
468 |
put '/issues/6.xml', @parameters, |
|
465 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
469 | end |
|
466 | end | |
470 | end |
|
467 | end | |
471 |
|
468 | |||
472 | should "not create a new journal" do |
|
469 | should "not create a new journal" do | |
473 | assert_no_difference('Journal.count') do |
|
470 | assert_no_difference('Journal.count') do | |
474 |
put '/issues/6.xml', @parameters, |
|
471 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
475 | end |
|
472 | end | |
476 | end |
|
473 | end | |
477 |
|
474 | |||
478 | should "have an errors tag" do |
|
475 | should "have an errors tag" do | |
479 |
put '/issues/6.xml', @parameters, |
|
476 | put '/issues/6.xml', @parameters, credentials('jsmith') | |
480 |
|
477 | |||
481 | assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} |
|
478 | assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} | |
482 | end |
|
479 | end | |
@@ -485,7 +482,6 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
485 | context "PUT /issues/6.json" do |
|
482 | context "PUT /issues/6.json" do | |
486 | setup do |
|
483 | setup do | |
487 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} |
|
484 | @parameters = {:issue => {:subject => 'API update', :notes => 'A new note'}} | |
488 | @headers = { :authorization => credentials('jsmith') } |
|
|||
489 | end |
|
485 | end | |
490 |
|
486 | |||
491 | should_allow_api_authentication(:put, |
|
487 | should_allow_api_authentication(:put, | |
@@ -495,25 +491,25 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
495 |
|
491 | |||
496 | should "not create a new issue" do |
|
492 | should "not create a new issue" do | |
497 | assert_no_difference('Issue.count') do |
|
493 | assert_no_difference('Issue.count') do | |
498 |
put '/issues/6.json', @parameters, |
|
494 | put '/issues/6.json', @parameters, credentials('jsmith') | |
499 | end |
|
495 | end | |
500 | end |
|
496 | end | |
501 |
|
497 | |||
502 | should "create a new journal" do |
|
498 | should "create a new journal" do | |
503 | assert_difference('Journal.count') do |
|
499 | assert_difference('Journal.count') do | |
504 |
put '/issues/6.json', @parameters, |
|
500 | put '/issues/6.json', @parameters, credentials('jsmith') | |
505 | end |
|
501 | end | |
506 | end |
|
502 | end | |
507 |
|
503 | |||
508 | should "add the note to the journal" do |
|
504 | should "add the note to the journal" do | |
509 |
put '/issues/6.json', @parameters, |
|
505 | put '/issues/6.json', @parameters, credentials('jsmith') | |
510 |
|
506 | |||
511 | journal = Journal.last |
|
507 | journal = Journal.last | |
512 | assert_equal "A new note", journal.notes |
|
508 | assert_equal "A new note", journal.notes | |
513 | end |
|
509 | end | |
514 |
|
510 | |||
515 | should "update the issue" do |
|
511 | should "update the issue" do | |
516 |
put '/issues/6.json', @parameters, |
|
512 | put '/issues/6.json', @parameters, credentials('jsmith') | |
517 |
|
513 | |||
518 | issue = Issue.find(6) |
|
514 | issue = Issue.find(6) | |
519 | assert_equal "API update", issue.subject |
|
515 | assert_equal "API update", issue.subject | |
@@ -524,23 +520,22 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
524 | context "PUT /issues/6.json with failed update" do |
|
520 | context "PUT /issues/6.json with failed update" do | |
525 | setup do |
|
521 | setup do | |
526 | @parameters = {:issue => {:subject => ''}} |
|
522 | @parameters = {:issue => {:subject => ''}} | |
527 | @headers = { :authorization => credentials('jsmith') } |
|
|||
528 | end |
|
523 | end | |
529 |
|
524 | |||
530 | should "not create a new issue" do |
|
525 | should "not create a new issue" do | |
531 | assert_no_difference('Issue.count') do |
|
526 | assert_no_difference('Issue.count') do | |
532 |
put '/issues/6.json', @parameters, |
|
527 | put '/issues/6.json', @parameters, credentials('jsmith') | |
533 | end |
|
528 | end | |
534 | end |
|
529 | end | |
535 |
|
530 | |||
536 | should "not create a new journal" do |
|
531 | should "not create a new journal" do | |
537 | assert_no_difference('Journal.count') do |
|
532 | assert_no_difference('Journal.count') do | |
538 |
put '/issues/6.json', @parameters, |
|
533 | put '/issues/6.json', @parameters, credentials('jsmith') | |
539 | end |
|
534 | end | |
540 | end |
|
535 | end | |
541 |
|
536 | |||
542 | should "have an errors attribute" do |
|
537 | should "have an errors attribute" do | |
543 |
put '/issues/6.json', @parameters, |
|
538 | put '/issues/6.json', @parameters, credentials('jsmith') | |
544 |
|
539 | |||
545 | json = ActiveSupport::JSON.decode(response.body) |
|
540 | json = ActiveSupport::JSON.decode(response.body) | |
546 | assert json['errors'].include?(['subject', "can't be blank"]) |
|
541 | assert json['errors'].include?(['subject', "can't be blank"]) | |
@@ -555,7 +550,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
555 |
|
550 | |||
556 | should "delete the issue" do |
|
551 | should "delete the issue" do | |
557 | assert_difference('Issue.count',-1) do |
|
552 | assert_difference('Issue.count',-1) do | |
558 |
delete '/issues/6.xml', {}, |
|
553 | delete '/issues/6.xml', {}, credentials('jsmith') | |
559 | end |
|
554 | end | |
560 |
|
555 | |||
561 | assert_nil Issue.find_by_id(6) |
|
556 | assert_nil Issue.find_by_id(6) | |
@@ -570,7 +565,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||||
570 |
|
565 | |||
571 | should "delete the issue" do |
|
566 | should "delete the issue" do | |
572 | assert_difference('Issue.count',-1) do |
|
567 | assert_difference('Issue.count',-1) do | |
573 |
delete '/issues/6.json', {}, |
|
568 | delete '/issues/6.json', {}, credentials('jsmith') | |
574 | end |
|
569 | end | |
575 |
|
570 | |||
576 | assert_nil Issue.find_by_id(6) |
|
571 | assert_nil Issue.find_by_id(6) |
@@ -152,7 +152,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
152 |
|
152 | |||
153 | should "create a project with the attributes" do |
|
153 | should "create a project with the attributes" do | |
154 | assert_difference('Project.count') do |
|
154 | assert_difference('Project.count') do | |
155 |
post '/projects.xml', @parameters, |
|
155 | post '/projects.xml', @parameters, credentials('admin') | |
156 | end |
|
156 | end | |
157 |
|
157 | |||
158 | project = Project.first(:order => 'id DESC') |
|
158 | project = Project.first(:order => 'id DESC') | |
@@ -170,7 +170,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
170 | @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) |
|
170 | @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) | |
171 |
|
171 | |||
172 | assert_difference('Project.count') do |
|
172 | assert_difference('Project.count') do | |
173 |
post '/projects.xml', @parameters, |
|
173 | post '/projects.xml', @parameters, credentials('admin') | |
174 | end |
|
174 | end | |
175 |
|
175 | |||
176 | project = Project.first(:order => 'id DESC') |
|
176 | project = Project.first(:order => 'id DESC') | |
@@ -181,7 +181,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
181 | @parameters[:project].merge!({:tracker_ids => [1, 3]}) |
|
181 | @parameters[:project].merge!({:tracker_ids => [1, 3]}) | |
182 |
|
182 | |||
183 | assert_difference('Project.count') do |
|
183 | assert_difference('Project.count') do | |
184 |
post '/projects.xml', @parameters, |
|
184 | post '/projects.xml', @parameters, credentials('admin') | |
185 | end |
|
185 | end | |
186 |
|
186 | |||
187 | project = Project.first(:order => 'id DESC') |
|
187 | project = Project.first(:order => 'id DESC') | |
@@ -198,7 +198,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
198 | context ".xml" do |
|
198 | context ".xml" do | |
199 | should "return errors" do |
|
199 | should "return errors" do | |
200 | assert_no_difference('Project.count') do |
|
200 | assert_no_difference('Project.count') do | |
201 |
post '/projects.xml', @parameters, |
|
201 | post '/projects.xml', @parameters, credentials('admin') | |
202 | end |
|
202 | end | |
203 |
|
203 | |||
204 | assert_response :unprocessable_entity |
|
204 | assert_response :unprocessable_entity | |
@@ -223,7 +223,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
223 |
|
223 | |||
224 | should "update the project" do |
|
224 | should "update the project" do | |
225 | assert_no_difference 'Project.count' do |
|
225 | assert_no_difference 'Project.count' do | |
226 |
put '/projects/2.xml', @parameters, |
|
226 | put '/projects/2.xml', @parameters, credentials('jsmith') | |
227 | end |
|
227 | end | |
228 | assert_response :ok |
|
228 | assert_response :ok | |
229 | assert_equal 'application/xml', @response.content_type |
|
229 | assert_equal 'application/xml', @response.content_type | |
@@ -235,7 +235,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
235 | @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) |
|
235 | @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}) | |
236 |
|
236 | |||
237 | assert_no_difference 'Project.count' do |
|
237 | assert_no_difference 'Project.count' do | |
238 |
put '/projects/2.xml', @parameters, |
|
238 | put '/projects/2.xml', @parameters, credentials('admin') | |
239 | end |
|
239 | end | |
240 | assert_response :ok |
|
240 | assert_response :ok | |
241 | project = Project.find(2) |
|
241 | project = Project.find(2) | |
@@ -246,7 +246,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
246 | @parameters[:project].merge!({:tracker_ids => [1, 3]}) |
|
246 | @parameters[:project].merge!({:tracker_ids => [1, 3]}) | |
247 |
|
247 | |||
248 | assert_no_difference 'Project.count' do |
|
248 | assert_no_difference 'Project.count' do | |
249 |
put '/projects/2.xml', @parameters, |
|
249 | put '/projects/2.xml', @parameters, credentials('admin') | |
250 | end |
|
250 | end | |
251 | assert_response :ok |
|
251 | assert_response :ok | |
252 | project = Project.find(2) |
|
252 | project = Project.find(2) | |
@@ -263,7 +263,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
263 | context ".xml" do |
|
263 | context ".xml" do | |
264 | should "return errors" do |
|
264 | should "return errors" do | |
265 | assert_no_difference('Project.count') do |
|
265 | assert_no_difference('Project.count') do | |
266 |
put '/projects/2.xml', @parameters, |
|
266 | put '/projects/2.xml', @parameters, credentials('admin') | |
267 | end |
|
267 | end | |
268 |
|
268 | |||
269 | assert_response :unprocessable_entity |
|
269 | assert_response :unprocessable_entity | |
@@ -283,7 +283,7 class ApiTest::ProjectsTest < ActionController::IntegrationTest | |||||
283 |
|
283 | |||
284 | should "delete the project" do |
|
284 | should "delete the project" do | |
285 | assert_difference('Project.count',-1) do |
|
285 | assert_difference('Project.count',-1) do | |
286 |
delete '/projects/2.xml', {}, |
|
286 | delete '/projects/2.xml', {}, credentials('admin') | |
287 | end |
|
287 | end | |
288 | assert_response :ok |
|
288 | assert_response :ok | |
289 | assert_nil Project.find_by_id(2) |
|
289 | assert_nil Project.find_by_id(2) |
@@ -34,7 +34,7 class ApiTest::TimeEntriesTest < ActionController::IntegrationTest | |||||
34 |
|
34 | |||
35 | context "GET /time_entries.xml" do |
|
35 | context "GET /time_entries.xml" do | |
36 | should "return time entries" do |
|
36 | should "return time entries" do | |
37 |
get '/time_entries.xml', {}, |
|
37 | get '/time_entries.xml', {}, credentials('jsmith') | |
38 | assert_response :success |
|
38 | assert_response :success | |
39 | assert_equal 'application/xml', @response.content_type |
|
39 | assert_equal 'application/xml', @response.content_type | |
40 | assert_tag :tag => 'time_entries', |
|
40 | assert_tag :tag => 'time_entries', | |
@@ -43,7 +43,7 class ApiTest::TimeEntriesTest < ActionController::IntegrationTest | |||||
43 |
|
43 | |||
44 | context "with limit" do |
|
44 | context "with limit" do | |
45 | should "return limited results" do |
|
45 | should "return limited results" do | |
46 |
get '/time_entries.xml?limit=2', {}, |
|
46 | get '/time_entries.xml?limit=2', {}, credentials('jsmith') | |
47 | assert_response :success |
|
47 | assert_response :success | |
48 | assert_equal 'application/xml', @response.content_type |
|
48 | assert_equal 'application/xml', @response.content_type | |
49 | assert_tag :tag => 'time_entries', |
|
49 | assert_tag :tag => 'time_entries', | |
@@ -54,7 +54,7 class ApiTest::TimeEntriesTest < ActionController::IntegrationTest | |||||
54 |
|
54 | |||
55 | context "GET /time_entries/2.xml" do |
|
55 | context "GET /time_entries/2.xml" do | |
56 | should "return requested time entry" do |
|
56 | should "return requested time entry" do | |
57 |
get '/time_entries/2.xml', {}, |
|
57 | get '/time_entries/2.xml', {}, credentials('jsmith') | |
58 | assert_response :success |
|
58 | assert_response :success | |
59 | assert_equal 'application/xml', @response.content_type |
|
59 | assert_equal 'application/xml', @response.content_type | |
60 | assert_tag :tag => 'time_entry', |
|
60 | assert_tag :tag => 'time_entry', | |
@@ -66,7 +66,7 class ApiTest::TimeEntriesTest < ActionController::IntegrationTest | |||||
66 | context "with issue_id" do |
|
66 | context "with issue_id" do | |
67 | should "return create time entry" do |
|
67 | should "return create time entry" do | |
68 | assert_difference 'TimeEntry.count' do |
|
68 | assert_difference 'TimeEntry.count' do | |
69 |
post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, |
|
69 | post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') | |
70 | end |
|
70 | end | |
71 | assert_response :created |
|
71 | assert_response :created | |
72 | assert_equal 'application/xml', @response.content_type |
|
72 | assert_equal 'application/xml', @response.content_type | |
@@ -84,7 +84,7 class ApiTest::TimeEntriesTest < ActionController::IntegrationTest | |||||
84 | context "with project_id" do |
|
84 | context "with project_id" do | |
85 | should "return create time entry" do |
|
85 | should "return create time entry" do | |
86 | assert_difference 'TimeEntry.count' do |
|
86 | assert_difference 'TimeEntry.count' do | |
87 |
post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, |
|
87 | post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') | |
88 | end |
|
88 | end | |
89 | assert_response :created |
|
89 | assert_response :created | |
90 | assert_equal 'application/xml', @response.content_type |
|
90 | assert_equal 'application/xml', @response.content_type | |
@@ -102,7 +102,7 class ApiTest::TimeEntriesTest < ActionController::IntegrationTest | |||||
102 | context "with invalid parameters" do |
|
102 | context "with invalid parameters" do | |
103 | should "return errors" do |
|
103 | should "return errors" do | |
104 | assert_no_difference 'TimeEntry.count' do |
|
104 | assert_no_difference 'TimeEntry.count' do | |
105 |
post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, |
|
105 | post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith') | |
106 | end |
|
106 | end | |
107 | assert_response :unprocessable_entity |
|
107 | assert_response :unprocessable_entity | |
108 | assert_equal 'application/xml', @response.content_type |
|
108 | assert_equal 'application/xml', @response.content_type | |
@@ -116,7 +116,7 class ApiTest::TimeEntriesTest < ActionController::IntegrationTest | |||||
116 | context "with valid parameters" do |
|
116 | context "with valid parameters" do | |
117 | should "update time entry" do |
|
117 | should "update time entry" do | |
118 | assert_no_difference 'TimeEntry.count' do |
|
118 | assert_no_difference 'TimeEntry.count' do | |
119 |
put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, |
|
119 | put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith') | |
120 | end |
|
120 | end | |
121 | assert_response :ok |
|
121 | assert_response :ok | |
122 | assert_equal 'API Update', TimeEntry.find(2).comments |
|
122 | assert_equal 'API Update', TimeEntry.find(2).comments | |
@@ -126,7 +126,7 class ApiTest::TimeEntriesTest < ActionController::IntegrationTest | |||||
126 | context "with invalid parameters" do |
|
126 | context "with invalid parameters" do | |
127 | should "return errors" do |
|
127 | should "return errors" do | |
128 | assert_no_difference 'TimeEntry.count' do |
|
128 | assert_no_difference 'TimeEntry.count' do | |
129 |
put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, |
|
129 | put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith') | |
130 | end |
|
130 | end | |
131 | assert_response :unprocessable_entity |
|
131 | assert_response :unprocessable_entity | |
132 | assert_equal 'application/xml', @response.content_type |
|
132 | assert_equal 'application/xml', @response.content_type | |
@@ -139,7 +139,7 class ApiTest::TimeEntriesTest < ActionController::IntegrationTest | |||||
139 | context "DELETE /time_entries/2.xml" do |
|
139 | context "DELETE /time_entries/2.xml" do | |
140 | should "destroy time entry" do |
|
140 | should "destroy time entry" do | |
141 | assert_difference 'TimeEntry.count', -1 do |
|
141 | assert_difference 'TimeEntry.count', -1 do | |
142 |
delete '/time_entries/2.xml', {}, |
|
142 | delete '/time_entries/2.xml', {}, credentials('jsmith') | |
143 | end |
|
143 | end | |
144 | assert_response :ok |
|
144 | assert_response :ok | |
145 | assert_nil TimeEntry.find_by_id(2) |
|
145 | assert_nil TimeEntry.find_by_id(2) |
@@ -60,7 +60,7 class ApiTest::UsersTest < ActionController::IntegrationTest | |||||
60 | end |
|
60 | end | |
61 |
|
61 | |||
62 | should "return current user" do |
|
62 | should "return current user" do | |
63 |
get '/users/current.xml', {}, |
|
63 | get '/users/current.xml', {}, credentials('jsmith') | |
64 |
|
64 | |||
65 | assert_tag :tag => 'user', |
|
65 | assert_tag :tag => 'user', | |
66 | :child => {:tag => 'id', :content => '2'} |
|
66 | :child => {:tag => 'id', :content => '2'} | |
@@ -91,7 +91,7 class ApiTest::UsersTest < ActionController::IntegrationTest | |||||
91 |
|
91 | |||
92 | should "create a user with the attributes" do |
|
92 | should "create a user with the attributes" do | |
93 | assert_difference('User.count') do |
|
93 | assert_difference('User.count') do | |
94 |
post '/users.xml', @parameters, |
|
94 | post '/users.xml', @parameters, credentials('admin') | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | user = User.first(:order => 'id DESC') |
|
97 | user = User.first(:order => 'id DESC') | |
@@ -120,7 +120,7 class ApiTest::UsersTest < ActionController::IntegrationTest | |||||
120 |
|
120 | |||
121 | should "create a user with the attributes" do |
|
121 | should "create a user with the attributes" do | |
122 | assert_difference('User.count') do |
|
122 | assert_difference('User.count') do | |
123 |
post '/users.json', @parameters, |
|
123 | post '/users.json', @parameters, credentials('admin') | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
126 | user = User.first(:order => 'id DESC') |
|
126 | user = User.first(:order => 'id DESC') | |
@@ -148,7 +148,7 class ApiTest::UsersTest < ActionController::IntegrationTest | |||||
148 | context ".xml" do |
|
148 | context ".xml" do | |
149 | should "return errors" do |
|
149 | should "return errors" do | |
150 | assert_no_difference('User.count') do |
|
150 | assert_no_difference('User.count') do | |
151 |
post '/users.xml', @parameters, |
|
151 | post '/users.xml', @parameters, credentials('admin') | |
152 | end |
|
152 | end | |
153 |
|
153 | |||
154 | assert_response :unprocessable_entity |
|
154 | assert_response :unprocessable_entity | |
@@ -163,7 +163,7 class ApiTest::UsersTest < ActionController::IntegrationTest | |||||
163 | context ".json" do |
|
163 | context ".json" do | |
164 | should "return errors" do |
|
164 | should "return errors" do | |
165 | assert_no_difference('User.count') do |
|
165 | assert_no_difference('User.count') do | |
166 |
post '/users.json', @parameters, |
|
166 | post '/users.json', @parameters, credentials('admin') | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | assert_response :unprocessable_entity |
|
169 | assert_response :unprocessable_entity | |
@@ -199,7 +199,7 class ApiTest::UsersTest < ActionController::IntegrationTest | |||||
199 |
|
199 | |||
200 | should "update user with the attributes" do |
|
200 | should "update user with the attributes" do | |
201 | assert_no_difference('User.count') do |
|
201 | assert_no_difference('User.count') do | |
202 |
put '/users/2.xml', @parameters, |
|
202 | put '/users/2.xml', @parameters, credentials('admin') | |
203 | end |
|
203 | end | |
204 |
|
204 | |||
205 | user = User.find(2) |
|
205 | user = User.find(2) | |
@@ -224,7 +224,7 class ApiTest::UsersTest < ActionController::IntegrationTest | |||||
224 |
|
224 | |||
225 | should "update user with the attributes" do |
|
225 | should "update user with the attributes" do | |
226 | assert_no_difference('User.count') do |
|
226 | assert_no_difference('User.count') do | |
227 |
put '/users/2.json', @parameters, |
|
227 | put '/users/2.json', @parameters, credentials('admin') | |
228 | end |
|
228 | end | |
229 |
|
229 | |||
230 | user = User.find(2) |
|
230 | user = User.find(2) | |
@@ -252,7 +252,7 class ApiTest::UsersTest < ActionController::IntegrationTest | |||||
252 | context ".xml" do |
|
252 | context ".xml" do | |
253 | should "return errors" do |
|
253 | should "return errors" do | |
254 | assert_no_difference('User.count') do |
|
254 | assert_no_difference('User.count') do | |
255 |
put '/users/2.xml', @parameters, |
|
255 | put '/users/2.xml', @parameters, credentials('admin') | |
256 | end |
|
256 | end | |
257 |
|
257 | |||
258 | assert_response :unprocessable_entity |
|
258 | assert_response :unprocessable_entity | |
@@ -267,7 +267,7 class ApiTest::UsersTest < ActionController::IntegrationTest | |||||
267 | context ".json" do |
|
267 | context ".json" do | |
268 | should "return errors" do |
|
268 | should "return errors" do | |
269 | assert_no_difference('User.count') do |
|
269 | assert_no_difference('User.count') do | |
270 |
put '/users/2.json', @parameters, |
|
270 | put '/users/2.json', @parameters, credentials('admin') | |
271 | end |
|
271 | end | |
272 |
|
272 | |||
273 | assert_response :unprocessable_entity |
|
273 | assert_response :unprocessable_entity | |
@@ -290,7 +290,7 class ApiTest::UsersTest < ActionController::IntegrationTest | |||||
290 |
|
290 | |||
291 | should "delete user" do |
|
291 | should "delete user" do | |
292 | assert_difference('User.count', -1) do |
|
292 | assert_difference('User.count', -1) do | |
293 |
delete '/users/2.xml', {}, |
|
293 | delete '/users/2.xml', {}, credentials('admin') | |
294 | end |
|
294 | end | |
295 |
|
295 | |||
296 | assert_response :ok |
|
296 | assert_response :ok | |
@@ -305,7 +305,7 class ApiTest::UsersTest < ActionController::IntegrationTest | |||||
305 |
|
305 | |||
306 | should "delete user" do |
|
306 | should "delete user" do | |
307 | assert_difference('User.count', -1) do |
|
307 | assert_difference('User.count', -1) do | |
308 |
delete '/users/2.json', {}, |
|
308 | delete '/users/2.json', {}, credentials('admin') | |
309 | end |
|
309 | end | |
310 |
|
310 | |||
311 | assert_response :ok |
|
311 | assert_response :ok |
@@ -58,7 +58,7 class ApiTest::VersionsTest < ActionController::IntegrationTest | |||||
58 | context "POST" do |
|
58 | context "POST" do | |
59 | should "create the version" do |
|
59 | should "create the version" do | |
60 | assert_difference 'Version.count' do |
|
60 | assert_difference 'Version.count' do | |
61 |
post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, |
|
61 | post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith') | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | version = Version.first(:order => 'id DESC') |
|
64 | version = Version.first(:order => 'id DESC') | |
@@ -72,7 +72,7 class ApiTest::VersionsTest < ActionController::IntegrationTest | |||||
72 | context "with failure" do |
|
72 | context "with failure" do | |
73 | should "return the errors" do |
|
73 | should "return the errors" do | |
74 | assert_no_difference('Version.count') do |
|
74 | assert_no_difference('Version.count') do | |
75 |
post '/projects/1/versions.xml', {:version => {:name => ''}}, |
|
75 | post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith') | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | assert_response :unprocessable_entity |
|
78 | assert_response :unprocessable_entity | |
@@ -103,7 +103,7 class ApiTest::VersionsTest < ActionController::IntegrationTest | |||||
103 |
|
103 | |||
104 | context "PUT" do |
|
104 | context "PUT" do | |
105 | should "update the version" do |
|
105 | should "update the version" do | |
106 |
put '/versions/2.xml', {:version => {:name => 'API update'}}, |
|
106 | put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith') | |
107 |
|
107 | |||
108 | assert_response :ok |
|
108 | assert_response :ok | |
109 | assert_equal 'API update', Version.find(2).name |
|
109 | assert_equal 'API update', Version.find(2).name | |
@@ -113,7 +113,7 class ApiTest::VersionsTest < ActionController::IntegrationTest | |||||
113 | context "DELETE" do |
|
113 | context "DELETE" do | |
114 | should "destroy the version" do |
|
114 | should "destroy the version" do | |
115 | assert_difference 'Version.count', -1 do |
|
115 | assert_difference 'Version.count', -1 do | |
116 |
delete '/versions/3.xml', {}, |
|
116 | delete '/versions/3.xml', {}, credentials('jsmith') | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | assert_response :ok |
|
119 | assert_response :ok |
@@ -63,7 +63,7 class ActiveSupport::TestCase | |||||
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | def credentials(user, password=nil) |
|
65 | def credentials(user, password=nil) | |
66 | ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) |
|
66 | {:authorization => ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)} | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | # Mock out a file |
|
69 | # Mock out a file | |
@@ -244,7 +244,7 class ActiveSupport::TestCase | |||||
244 | context "with a valid HTTP authentication" do |
|
244 | context "with a valid HTTP authentication" do | |
245 | setup do |
|
245 | setup do | |
246 | @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password', :admin => true) # Admin so they can access the project |
|
246 | @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password', :admin => true) # Admin so they can access the project | |
247 |
send(http_method, url, parameters, |
|
247 | send(http_method, url, parameters, credentials(@user.login, 'my_password')) | |
248 | end |
|
248 | end | |
249 |
|
249 | |||
250 | should_respond_with success_code |
|
250 | should_respond_with success_code | |
@@ -257,7 +257,7 class ActiveSupport::TestCase | |||||
257 | context "with an invalid HTTP authentication" do |
|
257 | context "with an invalid HTTP authentication" do | |
258 | setup do |
|
258 | setup do | |
259 | @user = User.generate_with_protected! |
|
259 | @user = User.generate_with_protected! | |
260 |
send(http_method, url, parameters, |
|
260 | send(http_method, url, parameters, credentials(@user.login, 'wrong_password')) | |
261 | end |
|
261 | end | |
262 |
|
262 | |||
263 | should_respond_with failure_code |
|
263 | should_respond_with failure_code | |
@@ -269,7 +269,7 class ActiveSupport::TestCase | |||||
269 |
|
269 | |||
270 | context "without credentials" do |
|
270 | context "without credentials" do | |
271 | setup do |
|
271 | setup do | |
272 |
send(http_method, url, parameters |
|
272 | send(http_method, url, parameters) | |
273 | end |
|
273 | end | |
274 |
|
274 | |||
275 | should_respond_with failure_code |
|
275 | should_respond_with failure_code | |
@@ -299,7 +299,7 class ActiveSupport::TestCase | |||||
299 | setup do |
|
299 | setup do | |
300 | @user = User.generate_with_protected!(:admin => true) |
|
300 | @user = User.generate_with_protected!(:admin => true) | |
301 | @token = Token.generate!(:user => @user, :action => 'api') |
|
301 | @token = Token.generate!(:user => @user, :action => 'api') | |
302 |
send(http_method, url, parameters, |
|
302 | send(http_method, url, parameters, credentials(@token.value, 'X')) | |
303 | end |
|
303 | end | |
304 |
|
304 | |||
305 | should_respond_with success_code |
|
305 | should_respond_with success_code | |
@@ -314,7 +314,7 class ActiveSupport::TestCase | |||||
314 | setup do |
|
314 | setup do | |
315 | @user = User.generate_with_protected! |
|
315 | @user = User.generate_with_protected! | |
316 | @token = Token.generate!(:user => @user, :action => 'feeds') |
|
316 | @token = Token.generate!(:user => @user, :action => 'feeds') | |
317 |
send(http_method, url, parameters, |
|
317 | send(http_method, url, parameters, credentials(@token.value, 'X')) | |
318 | end |
|
318 | end | |
319 |
|
319 | |||
320 | should_respond_with failure_code |
|
320 | should_respond_with failure_code |
General Comments 0
You need to be logged in to leave comments.
Login now