diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-06-01 18:17:27 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-06-01 18:17:27 +0000 |
commit | 966f238da459fda40be8db48904dad7e4266a443 (patch) | |
tree | 33932b6969f6a6a55e8f8c6461de2c837d03ca07 /test/integration/api_test | |
parent | b834e81d7f41121fc6d9bef95ee090f8f466493e (diff) | |
download | redmine-966f238da459fda40be8db48904dad7e4266a443.tar.gz redmine-966f238da459fda40be8db48904dad7e4266a443.zip |
Use Rails 5 syntax for integration tests.
git-svn-id: http://svn.redmine.org/redmine/trunk@16586 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/integration/api_test')
18 files changed, 449 insertions, 271 deletions
diff --git a/test/integration/api_test/api_test.rb b/test/integration/api_test/api_test.rb index 74e95d24d..69b6166a4 100644 --- a/test/integration/api_test/api_test.rb +++ b/test/integration/api_test/api_test.rb @@ -23,12 +23,13 @@ class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base def test_api_should_work_with_protect_from_forgery ActionController::Base.allow_forgery_protection = true assert_difference('User.count') do - post '/users.xml', { - :user => { - :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', - :mail => 'foo@example.net', :password => 'secret123'} - }, - credentials('admin') + post '/users.xml', + :params => { + :user => { + :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', + :mail => 'foo@example.net', :password => 'secret123'} + }, + :headers => credentials('admin') assert_response 201 end ensure @@ -36,17 +37,17 @@ class Redmine::ApiTest::ApiTest < Redmine::ApiTest::Base end def test_json_datetime_format - get '/users/1.json', {}, credentials('admin') + get '/users/1.json', :headers => credentials('admin') assert_include '"created_on":"2006-07-19T17:12:21Z"', response.body end def test_xml_datetime_format - get '/users/1.xml', {}, credentials('admin') + get '/users/1.xml', :headers => credentials('admin') assert_include '<created_on>2006-07-19T17:12:21Z</created_on>', response.body end def test_head_response_should_have_empty_body - put '/users/7.xml', {:user => {:login => 'foo'}}, credentials('admin') + put '/users/7.xml', :params => {:user => {:login => 'foo'}}, :headers => credentials('admin') assert_response :ok assert_equal '', response.body diff --git a/test/integration/api_test/attachments_test.rb b/test/integration/api_test/attachments_test.rb index 641dccabf..9d5e2628e 100644 --- a/test/integration/api_test/attachments_test.rb +++ b/test/integration/api_test/attachments_test.rb @@ -38,7 +38,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base end test "GET /attachments/:id.xml should return the attachment" do - get '/attachments/7.xml', {}, credentials('jsmith') + get '/attachments/7.xml', :headers => credentials('jsmith') assert_response :success assert_equal 'application/xml', @response.content_type assert_select 'attachment id', :text => '7' do @@ -48,7 +48,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base end test "GET /attachments/:id.xml for image should include thumbnail_url" do - get '/attachments/16.xml', {}, credentials('jsmith') + get '/attachments/16.xml', :headers => credentials('jsmith') assert_response :success assert_equal 'application/xml', @response.content_type assert_select 'attachment id:contains(16)' do @@ -63,7 +63,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base end test "GET /attachments/download/:id/:filename should return the attachment content" do - get '/attachments/download/7/archive.zip', {}, credentials('jsmith') + get '/attachments/download/7/archive.zip', :headers => credentials('jsmith') assert_response :success assert_equal 'application/zip', @response.content_type set_tmp_attachments_directory @@ -77,13 +77,13 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base test "GET /attachments/thumbnail/:id should return the thumbnail" do skip unless convert_installed? - get '/attachments/thumbnail/16', {}, credentials('jsmith') + get '/attachments/thumbnail/16', :headers => credentials('jsmith') assert_response :success end test "DELETE /attachments/:id.xml should return ok and delete Attachment" do assert_difference 'Attachment.count', -1 do - delete '/attachments/7.xml', {}, credentials('jsmith') + delete '/attachments/7.xml', :headers => credentials('jsmith') assert_response :ok assert_equal '', response.body end @@ -92,7 +92,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base test "DELETE /attachments/:id.json should return ok and delete Attachment" do assert_difference 'Attachment.count', -1 do - delete '/attachments/7.json', {}, credentials('jsmith') + delete '/attachments/7.json', :headers => credentials('jsmith') assert_response :ok assert_equal '', response.body end @@ -101,8 +101,8 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base test "PATCH /attachments/:id.json should update the attachment" do patch '/attachments/7.json', - {:attachment => {:filename => 'renamed.zip', :description => 'updated'}}, - credentials('jsmith') + :params => {:attachment => {:filename => 'renamed.zip', :description => 'updated'}}, + :headers => credentials('jsmith') assert_response :ok assert_equal 'application/json', response.content_type @@ -113,8 +113,8 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base test "PATCH /attachments/:id.json with failure should return the errors" do patch '/attachments/7.json', - {:attachment => {:filename => '', :description => 'updated'}}, - credentials('jsmith') + :params => {:attachment => {:filename => '', :description => 'updated'}}, + :headers => credentials('jsmith') assert_response 422 assert_equal 'application/json', response.content_type @@ -125,7 +125,10 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base test "POST /uploads.xml should return the token" do set_tmp_attachments_directory assert_difference 'Attachment.count' do - post '/uploads.xml', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) + post '/uploads.xml', :headers => { + "RAW_POST_DATA" => 'File content', + "CONTENT_TYPE" => 'application/octet-stream' + }.merge(credentials('jsmith')) assert_response :created assert_equal 'application/xml', response.content_type end @@ -145,7 +148,7 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base assert_equal 'File content'.size, attachment.filesize assert attachment.content_type.blank? assert attachment.filename.present? - assert_match /\d+_[0-9a-z]+/, attachment.diskfile + assert_match %r{\d+_[0-9a-z]+}, attachment.diskfile assert File.exist?(attachment.diskfile) assert_equal 'File content', File.read(attachment.diskfile) end @@ -153,7 +156,10 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base test "POST /uploads.json should return the token" do set_tmp_attachments_directory assert_difference 'Attachment.count' do - post '/uploads.json', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) + post '/uploads.json', :headers => { + "RAW_POST_DATA" => 'File content', + "CONTENT_TYPE" => 'application/octet-stream' + }.merge(credentials('jsmith')) assert_response :created assert_equal 'application/json', response.content_type end @@ -170,7 +176,10 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base test "POST /uploads.xml should accept :filename param as the attachment filename" do set_tmp_attachments_directory assert_difference 'Attachment.count' do - post '/uploads.xml?filename=test.txt', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) + post '/uploads.xml?filename=test.txt', :headers => { + "RAW_POST_DATA" => 'File content', + "CONTENT_TYPE" => 'application/octet-stream' + }.merge(credentials('jsmith')) assert_response :created end @@ -182,7 +191,10 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base test "POST /uploads.xml should not accept other content types" do set_tmp_attachments_directory assert_no_difference 'Attachment.count' do - post '/uploads.xml', 'PNG DATA', {"CONTENT_TYPE" => 'image/png'}.merge(credentials('jsmith')) + post '/uploads.xml', :headers => { + "RAW_POST_DATA" => 'PNG DATA', + "CONTENT_TYPE" => 'image/png' + }.merge(credentials('jsmith')) assert_response 406 end end @@ -191,7 +203,10 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base set_tmp_attachments_directory with_settings :attachment_max_size => 1 do assert_no_difference 'Attachment.count' do - post '/uploads.xml', ('x' * 2048), {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) + post '/uploads.xml', :headers => { + "RAW_POST_DATA" => ('x' * 2048), + "CONTENT_TYPE" => 'application/octet-stream' + }.merge(credentials('jsmith')) assert_response 422 assert_select 'error', :text => /exceeds the maximum allowed file size/ end @@ -201,7 +216,9 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base test "POST /uploads.json should create an empty file and return a valid token" do set_tmp_attachments_directory assert_difference 'Attachment.count' do - post '/uploads.json', '', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) + post '/uploads.json', :headers => { + "CONTENT_TYPE" => 'application/octet-stream' + }.merge(credentials('jsmith')) assert_response :created end diff --git a/test/integration/api_test/authentication_test.rb b/test/integration/api_test/authentication_test.rb index 887436f1d..f7e5b82a1 100644 --- a/test/integration/api_test/authentication_test.rb +++ b/test/integration/api_test/authentication_test.rb @@ -21,7 +21,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base fixtures :users def test_api_should_deny_without_credentials - get '/users/current.xml', {} + get '/users/current.xml' assert_response 401 assert_equal User.anonymous, User.current assert response.headers.has_key?('WWW-Authenticate') @@ -31,7 +31,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base user = User.generate! do |user| user.password = 'my_password' end - get '/users/current.xml', {}, credentials(user.login, 'my_password') + get '/users/current.xml', :headers => credentials(user.login, 'my_password') assert_response 200 assert_equal user, User.current end @@ -40,7 +40,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base user = User.generate! do |user| user.password = 'my_password' end - get '/users/current.xml', {}, credentials(user.login, 'wrong_password') + get '/users/current.xml', :headers => credentials(user.login, 'wrong_password') assert_response 401 assert_equal User.anonymous, User.current end @@ -48,7 +48,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base def test_api_should_accept_http_basic_auth_using_api_key user = User.generate! token = Token.create!(:user => user, :action => 'api') - get '/users/current.xml', {}, credentials(token.value, 'X') + get '/users/current.xml', :headers => credentials(token.value, 'X') assert_response 200 assert_equal user, User.current end @@ -56,7 +56,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base def test_api_should_deny_http_basic_auth_using_wrong_api_key user = User.generate! token = Token.create!(:user => user, :action => 'feeds') # not the API key - get '/users/current.xml', {}, credentials(token.value, 'X') + get '/users/current.xml', :headers => credentials(token.value, 'X') assert_response 401 assert_equal User.anonymous, User.current end @@ -64,7 +64,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base def test_api_should_accept_auth_using_api_key_as_parameter user = User.generate! token = Token.create!(:user => user, :action => 'api') - get "/users/current.xml?key=#{token.value}", {} + get "/users/current.xml?key=#{token.value}" assert_response 200 assert_equal user, User.current end @@ -72,7 +72,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base def test_api_should_deny_auth_using_wrong_api_key_as_parameter user = User.generate! token = Token.create!(:user => user, :action => 'feeds') # not the API key - get "/users/current.xml?key=#{token.value}", {} + get "/users/current.xml?key=#{token.value}" assert_response 401 assert_equal User.anonymous, User.current end @@ -80,7 +80,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base def test_api_should_accept_auth_using_api_key_as_request_header user = User.generate! token = Token.create!(:user => user, :action => 'api') - get "/users/current.xml", {}, {'X-Redmine-API-Key' => token.value.to_s} + get "/users/current.xml", :headers => {'X-Redmine-API-Key' => token.value.to_s} assert_response 200 assert_equal user, User.current end @@ -88,20 +88,20 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base def test_api_should_deny_auth_using_wrong_api_key_as_request_header user = User.generate! token = Token.create!(:user => user, :action => 'feeds') # not the API key - get "/users/current.xml", {}, {'X-Redmine-API-Key' => token.value.to_s} + get "/users/current.xml", :headers => {'X-Redmine-API-Key' => token.value.to_s} assert_response 401 assert_equal User.anonymous, User.current end def test_api_should_trigger_basic_http_auth_with_basic_authorization_header ApplicationController.any_instance.expects(:authenticate_with_http_basic).once - get '/users/current.xml', {}, credentials('jsmith') + get '/users/current.xml', :headers => credentials('jsmith') assert_response 401 end def test_api_should_not_trigger_basic_http_auth_with_non_basic_authorization_header ApplicationController.any_instance.expects(:authenticate_with_http_basic).never - get '/users/current.xml', {}, 'HTTP_AUTHORIZATION' => 'Digest foo bar' + get '/users/current.xml', :headers => {'HTTP_AUTHORIZATION' => 'Digest foo bar'} assert_response 401 end @@ -109,7 +109,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base invalid_utf8 = "\x82".force_encoding('UTF-8') assert !invalid_utf8.valid_encoding? assert_nothing_raised do - get '/users/current.xml', {}, credentials(invalid_utf8, "foo") + get '/users/current.xml', :headers => credentials(invalid_utf8, "foo") end end @@ -127,14 +127,14 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base user = User.find(1) su = User.find(4) - get '/users/current', {}, {'X-Redmine-API-Key' => user.api_key, 'X-Redmine-Switch-User' => su.login} + get '/users/current', :headers => {'X-Redmine-API-Key' => user.api_key, 'X-Redmine-Switch-User' => su.login} assert_response :success assert_select 'h2', :text => su.name assert_equal su, User.current end def test_api_should_respond_with_412_when_trying_to_switch_to_a_invalid_user - get '/users/current', {}, {'X-Redmine-API-Key' => User.find(1).api_key, 'X-Redmine-Switch-User' => 'foobar'} + get '/users/current', :headers => {'X-Redmine-API-Key' => User.find(1).api_key, 'X-Redmine-Switch-User' => 'foobar'} assert_response 412 end @@ -142,7 +142,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base user = User.find(5) assert user.locked? - get '/users/current', {}, {'X-Redmine-API-Key' => User.find(1).api_key, 'X-Redmine-Switch-User' => user.login} + get '/users/current', :headers => {'X-Redmine-API-Key' => User.find(1).api_key, 'X-Redmine-Switch-User' => user.login} assert_response 412 end @@ -150,7 +150,7 @@ class Redmine::ApiTest::AuthenticationTest < Redmine::ApiTest::Base user = User.find(2) su = User.find(4) - get '/users/current', {}, {'X-Redmine-API-Key' => user.api_key, 'X-Redmine-Switch-User' => su.login} + get '/users/current', :headers => {'X-Redmine-API-Key' => user.api_key, 'X-Redmine-Switch-User' => su.login} assert_response :success assert_select 'h2', :text => user.name assert_equal user, User.current diff --git a/test/integration/api_test/custom_fields_attribute_test.rb b/test/integration/api_test/custom_fields_attribute_test.rb index 401b06506..66e00f36e 100644 --- a/test/integration/api_test/custom_fields_attribute_test.rb +++ b/test/integration/api_test/custom_fields_attribute_test.rb @@ -23,8 +23,11 @@ class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base def test_integer_custom_fields_should_accept_strings field = GroupCustomField.generate!(:field_format => 'int') - post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":"52"}}}), - {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin')) + post '/groups.json', + :params => %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":"52"}}}), + :headers => { + 'CONTENT_TYPE' => 'application/json' + }.merge(credentials('admin')) assert_response :created group = Group.order('id DESC').first assert_equal "52", group.custom_field_value(field) @@ -33,8 +36,11 @@ class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base def test_integer_custom_fields_should_accept_integers field = GroupCustomField.generate!(:field_format => 'int') - post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":52}}}), - {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin')) + post '/groups.json', + :params => %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":52}}}), + :headers => { + 'CONTENT_TYPE' => 'application/json' + }.merge(credentials('admin')) assert_response :created group = Group.order('id DESC').first assert_equal "52", group.custom_field_value(field) @@ -43,8 +49,11 @@ class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base def test_boolean_custom_fields_should_accept_strings field = GroupCustomField.generate!(:field_format => 'bool') - post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}": "1"}}}), - {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin')) + post '/groups.json', + :params => %({"group":{"name":"Foo","custom_field_values":{"#{field.id}": "1"}}}), + :headers => { + 'CONTENT_TYPE' => 'application/json' + }.merge(credentials('admin')) assert_response :created group = Group.order('id DESC').first assert_equal "1", group.custom_field_value(field) @@ -53,8 +62,11 @@ class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base def test_boolean_custom_fields_should_accept_integers field = GroupCustomField.generate!(:field_format => 'bool') - post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}": 1}}}), - {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin')) + post '/groups.json', + :params => %({"group":{"name":"Foo","custom_field_values":{"#{field.id}": 1}}}), + :headers => { + 'CONTENT_TYPE' => 'application/json' + }.merge(credentials('admin')) assert_response :created group = Group.order('id DESC').first assert_equal "1", group.custom_field_value(field) @@ -75,7 +87,11 @@ payload = <<-JSON } JSON - post '/groups.json', payload, {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin')) + post '/groups.json', + :params => payload, + :headers => { + 'CONTENT_TYPE' => 'application/json' + }.merge(credentials('admin')) assert_response :created group = Group.order('id DESC').first assert_equal ["V1", "V3"], group.custom_field_value(field).sort diff --git a/test/integration/api_test/custom_fields_test.rb b/test/integration/api_test/custom_fields_test.rb index c3efa6b9b..27bf1a485 100644 --- a/test/integration/api_test/custom_fields_test.rb +++ b/test/integration/api_test/custom_fields_test.rb @@ -21,7 +21,7 @@ class Redmine::ApiTest::CustomFieldsTest < Redmine::ApiTest::Base fixtures :users, :custom_fields test "GET /custom_fields.xml should return custom fields" do - get '/custom_fields.xml', {}, credentials('admin') + get '/custom_fields.xml', :headers => credentials('admin') assert_response :success assert_equal 'application/xml', response.content_type @@ -45,7 +45,7 @@ class Redmine::ApiTest::CustomFieldsTest < Redmine::ApiTest::Base foo = field.enumerations.create!(:name => 'Foo') bar = field.enumerations.create!(:name => 'Bar') - get '/custom_fields.xml', {}, credentials('admin') + get '/custom_fields.xml', :headers => credentials('admin') assert_response :success assert_select 'possible_value' do diff --git a/test/integration/api_test/disabled_rest_api_test.rb b/test/integration/api_test/disabled_rest_api_test.rb index 224820696..7313c0e0e 100644 --- a/test/integration/api_test/disabled_rest_api_test.rb +++ b/test/integration/api_test/disabled_rest_api_test.rb @@ -54,11 +54,11 @@ class Redmine::ApiTest::DisabledRestApiTest < Redmine::ApiTest::Base user.password = 'my_password' end - get "/news.xml", nil, credentials(@user.login, 'my_password') + get "/news.xml", :headers => credentials(@user.login, 'my_password') assert_response :unauthorized assert_equal User.anonymous, User.current - get "/news.json", nil, credentials(@user.login, 'my_password') + get "/news.json", :headers => credentials(@user.login, 'my_password') assert_response :unauthorized assert_equal User.anonymous, User.current end @@ -67,11 +67,11 @@ class Redmine::ApiTest::DisabledRestApiTest < Redmine::ApiTest::Base @user = User.generate! @token = Token.create!(:user => @user, :action => 'api') - get "/news.xml", nil, credentials(@token.value, 'X') + get "/news.xml", :headers => credentials(@token.value, 'X') assert_response :unauthorized assert_equal User.anonymous, User.current - get "/news.json", nil, credentials(@token.value, 'X') + get "/news.json", :headers => credentials(@token.value, 'X') assert_response :unauthorized assert_equal User.anonymous, User.current end diff --git a/test/integration/api_test/files_test.rb b/test/integration/api_test/files_test.rb index caef7f66a..0b355c42c 100644 --- a/test/integration/api_test/files_test.rb +++ b/test/integration/api_test/files_test.rb @@ -28,14 +28,16 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base :versions test "GET /projects/:project_id/files.xml should return the list of uploaded files" do - get '/projects/1/files.xml', {}, credentials('jsmith') + get '/projects/1/files.xml', :headers => credentials('jsmith') assert_response :success assert_select 'files>file>id', :text => '8' end test "POST /projects/:project_id/files.json should create a file" do set_tmp_attachments_directory - post '/uploads.xml', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) + post '/uploads.xml', + :params => 'File content', + :headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) token = Attachment.last.token payload = <<-JSON { "file": { @@ -43,7 +45,9 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base } } JSON - post '/projects/1/files.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) + post '/projects/1/files.json', + :params => payload, + :headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) assert_response :success assert_equal 1, Attachment.last.container_id assert_equal "Project", Attachment.last.container_type @@ -51,14 +55,18 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base test "POST /projects/:project_id/files.xml should create a file" do set_tmp_attachments_directory - post '/uploads.xml', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) + post '/uploads.xml', + :params => 'File content', + :headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) token = Attachment.last.token payload = <<-XML <file> <token>#{token}</token> </file> XML - post '/projects/1/files.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')) + post '/projects/1/files.xml', + :params => payload, + :headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')) assert_response :success assert_equal 1, Attachment.last.container_id assert_equal "Project", Attachment.last.container_type @@ -71,13 +79,17 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base } } JSON - post '/projects/1/files.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) + post '/projects/1/files.json', + :params => payload, + :headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) assert_response :bad_request end test "POST /projects/:project_id/files.json should accept :filename, :description, :content_type as optional parameters" do set_tmp_attachments_directory - post '/uploads.xml', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) + post '/uploads.xml', + :params => 'File content', + :headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) token = Attachment.last.token payload = <<-JSON { "file": { @@ -88,7 +100,9 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base } } JSON - post '/projects/1/files.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) + post '/projects/1/files.json', + :params => payload, + :headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) assert_response :success assert_equal "New filename", Attachment.last.filename assert_equal "New description", Attachment.last.description @@ -97,7 +111,9 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base test "POST /projects/:project_id/files.json should accept :version_id to attach the files to a version" do set_tmp_attachments_directory - post '/uploads.xml', 'File content', {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) + post '/uploads.xml', + :params => 'File content', + :headers => {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials('jsmith')) token = Attachment.last.token payload = <<-JSON { "file": { @@ -108,7 +124,9 @@ class Redmine::ApiTest::FilesTest < Redmine::ApiTest::Base } } JSON - post '/projects/1/files.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) + post '/projects/1/files.json', + :params => payload, + :headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) assert_equal 3, Attachment.last.container_id assert_equal "Version", Attachment.last.container_type end diff --git a/test/integration/api_test/groups_test.rb b/test/integration/api_test/groups_test.rb index c9f79f242..b1626a9f0 100644 --- a/test/integration/api_test/groups_test.rb +++ b/test/integration/api_test/groups_test.rb @@ -26,7 +26,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base end test "GET /groups.xml should return givable groups" do - get '/groups.xml', {}, credentials('admin') + get '/groups.xml', :headers => credentials('admin') assert_response :success assert_equal 'application/xml', response.content_type @@ -40,7 +40,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base end test "GET /groups.xml?builtin=1 should return all groups" do - get '/groups.xml?builtin=1', {}, credentials('admin') + get '/groups.xml?builtin=1', :headers => credentials('admin') assert_response :success assert_equal 'application/xml', response.content_type @@ -63,7 +63,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base end test "GET /groups.json should return groups" do - get '/groups.json', {}, credentials('admin') + get '/groups.json', :headers => credentials('admin') assert_response :success assert_equal 'application/json', response.content_type @@ -76,7 +76,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base end test "GET /groups/:id.xml should return the group" do - get '/groups/10.xml', {}, credentials('admin') + get '/groups/10.xml', :headers => credentials('admin') assert_response :success assert_equal 'application/xml', response.content_type @@ -87,7 +87,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base end test "GET /groups/:id.xml should return the builtin group" do - get '/groups/12.xml', {}, credentials('admin') + get '/groups/12.xml', :headers => credentials('admin') assert_response :success assert_equal 'application/xml', response.content_type @@ -98,7 +98,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base end test "GET /groups/:id.xml should include users if requested" do - get '/groups/10.xml?include=users', {}, credentials('admin') + get '/groups/10.xml?include=users', :headers => credentials('admin') assert_response :success assert_equal 'application/xml', response.content_type @@ -111,7 +111,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base end test "GET /groups/:id.xml include memberships if requested" do - get '/groups/10.xml?include=memberships', {}, credentials('admin') + get '/groups/10.xml?include=memberships', :headers => credentials('admin') assert_response :success assert_equal 'application/xml', response.content_type @@ -122,7 +122,9 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base test "POST /groups.xml with valid parameters should create the group" do assert_difference('Group.count') do - post '/groups.xml', {:group => {:name => 'Test', :user_ids => [2, 3]}}, credentials('admin') + post '/groups.xml', + :params => {:group => {:name => 'Test', :user_ids => [2, 3]}}, + :headers => credentials('admin') assert_response :created assert_equal 'application/xml', response.content_type end @@ -138,7 +140,9 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base test "POST /groups.xml with invalid parameters should return errors" do assert_no_difference('Group.count') do - post '/groups.xml', {:group => {:name => ''}}, credentials('admin') + post '/groups.xml', + :params => {:group => {:name => ''}}, + :headers => credentials('admin') end assert_response :unprocessable_entity assert_equal 'application/xml', response.content_type @@ -150,7 +154,9 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base test "PUT /groups/:id.xml with valid parameters should update the group" do group = Group.generate! - put "/groups/#{group.id}.xml", {:group => {:name => 'New name', :user_ids => [2, 3]}}, credentials('admin') + put "/groups/#{group.id}.xml", + :params => {:group => {:name => 'New name', :user_ids => [2, 3]}}, + :headers => credentials('admin') assert_response :ok assert_equal '', @response.body @@ -160,7 +166,9 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base test "PUT /groups/:id.xml with invalid parameters should return errors" do group = Group.generate! - put "/groups/#{group.id}.xml", {:group => {:name => ''}}, credentials('admin') + put "/groups/#{group.id}.xml", + :params => {:group => {:name => ''}}, + :headers => credentials('admin') assert_response :unprocessable_entity assert_equal 'application/xml', response.content_type @@ -172,7 +180,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base test "DELETE /groups/:id.xml should delete the group" do group = Group.generate! assert_difference 'Group.count', -1 do - delete "/groups/#{group.id}.xml", {}, credentials('admin') + delete "/groups/#{group.id}.xml", :headers => credentials('admin') assert_response :ok assert_equal '', @response.body end @@ -181,7 +189,9 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base test "POST /groups/:id/users.xml should add user to the group" do group = Group.generate! assert_difference 'group.reload.users.count' do - post "/groups/#{group.id}/users.xml", {:user_id => 5}, credentials('admin') + post "/groups/#{group.id}/users.xml", + :params => {:user_id => 5}, + :headers => credentials('admin') assert_response :ok assert_equal '', @response.body end @@ -193,7 +203,9 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base group.users << User.find(5) assert_no_difference 'group.reload.users.count' do - post "/groups/#{group.id}/users.xml", {:user_id => 5}, credentials('admin') + post "/groups/#{group.id}/users.xml", + :params => {:user_id => 5}, + :headers => credentials('admin') assert_response :unprocessable_entity end @@ -207,7 +219,7 @@ class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base group.users << User.find(8) assert_difference 'group.reload.users.count', -1 do - delete "/groups/#{group.id}/users/8.xml", {}, credentials('admin') + delete "/groups/#{group.id}/users/8.xml", :headers => credentials('admin') assert_response :ok assert_equal '', @response.body end diff --git a/test/integration/api_test/issue_categories_test.rb b/test/integration/api_test/issue_categories_test.rb index f9083a768..8d19d6c9f 100644 --- a/test/integration/api_test/issue_categories_test.rb +++ b/test/integration/api_test/issue_categories_test.rb @@ -25,14 +25,14 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base :enabled_modules test "GET /projects/:project_id/issue_categories.xml should return the issue categories" do - get '/projects/1/issue_categories.xml', {}, credentials('jsmith') + get '/projects/1/issue_categories.xml', :headers => credentials('jsmith') assert_response :success assert_equal 'application/xml', @response.content_type assert_select 'issue_categories issue_category id', :text => '2' end test "GET /issue_categories/:id.xml should return the issue category" do - get '/issue_categories/2.xml', {}, credentials('jsmith') + get '/issue_categories/2.xml', :headers => credentials('jsmith') assert_response :success assert_equal 'application/xml', @response.content_type assert_select 'issue_category id', :text => '2' @@ -40,7 +40,9 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base test "POST /projects/:project_id/issue_categories.xml should return create issue category" do assert_difference 'IssueCategory.count' do - post '/projects/1/issue_categories.xml', {:issue_category => {:name => 'API'}}, credentials('jsmith') + post '/projects/1/issue_categories.xml', + :params => {:issue_category => {:name => 'API'}}, + :headers => credentials('jsmith') end assert_response :created assert_equal 'application/xml', @response.content_type @@ -52,7 +54,9 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base test "POST /projects/:project_id/issue_categories.xml with invalid parameters should return errors" do assert_no_difference 'IssueCategory.count' do - post '/projects/1/issue_categories.xml', {:issue_category => {:name => ''}}, credentials('jsmith') + post '/projects/1/issue_categories.xml', + :params => {:issue_category => {:name => ''}}, + :headers => credentials('jsmith') end assert_response :unprocessable_entity assert_equal 'application/xml', @response.content_type @@ -62,7 +66,9 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base test "PUT /issue_categories/:id.xml with valid parameters should update the issue category" do assert_no_difference 'IssueCategory.count' do - put '/issue_categories/2.xml', {:issue_category => {:name => 'API Update'}}, credentials('jsmith') + put '/issue_categories/2.xml', + :params => {:issue_category => {:name => 'API Update'}}, + :headers => credentials('jsmith') end assert_response :ok assert_equal '', @response.body @@ -71,7 +77,9 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base test "PUT /issue_categories/:id.xml with invalid parameters should return errors" do assert_no_difference 'IssueCategory.count' do - put '/issue_categories/2.xml', {:issue_category => {:name => ''}}, credentials('jsmith') + put '/issue_categories/2.xml', + :params => {:issue_category => {:name => ''}}, + :headers => credentials('jsmith') end assert_response :unprocessable_entity assert_equal 'application/xml', @response.content_type @@ -81,7 +89,7 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base test "DELETE /issue_categories/:id.xml should destroy the issue category" do assert_difference 'IssueCategory.count', -1 do - delete '/issue_categories/1.xml', {}, credentials('jsmith') + delete '/issue_categories/1.xml', :headers => credentials('jsmith') end assert_response :ok assert_equal '', @response.body @@ -94,7 +102,9 @@ class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base assert_difference 'IssueCategory.count', -1 do assert_difference 'Issue.where(:category_id => 2).count', 3 do - delete '/issue_categories/1.xml', {:reassign_to_id => 2}, credentials('jsmith') + delete '/issue_categories/1.xml', + :params => {:reassign_to_id => 2}, + :headers => credentials('jsmith') end end assert_response :ok diff --git a/test/integration/api_test/issue_relations_test.rb b/test/integration/api_test/issue_relations_test.rb index 752cb3fe3..17948afa9 100644 --- a/test/integration/api_test/issue_relations_test.rb +++ b/test/integration/api_test/issue_relations_test.rb @@ -28,7 +28,7 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base :issue_relations test "GET /issues/:issue_id/relations.xml should return issue relations" do - get '/issues/9/relations.xml', {}, credentials('jsmith') + get '/issues/9/relations.xml', :headers => credentials('jsmith') assert_response :success assert_equal 'application/xml', @response.content_type @@ -38,7 +38,9 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base test "POST /issues/:issue_id/relations.xml should create the relation" do assert_difference('IssueRelation.count') do - post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, credentials('jsmith') + post '/issues/2/relations.xml', + :params => {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, + :headers => credentials('jsmith') end relation = IssueRelation.order('id DESC').first @@ -53,7 +55,9 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base test "POST /issues/:issue_id/relations.xml with failure should return errors" do assert_no_difference('IssueRelation.count') do - post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, credentials('jsmith') + post '/issues/2/relations.xml', + :params => {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, + :headers => credentials('jsmith') end assert_response :unprocessable_entity @@ -61,7 +65,7 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base end test "GET /relations/:id.xml should return the relation" do - get '/relations/2.xml', {}, credentials('jsmith') + get '/relations/2.xml', :headers => credentials('jsmith') assert_response :success assert_equal 'application/xml', @response.content_type @@ -70,7 +74,7 @@ class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base test "DELETE /relations/:id.xml should delete the relation" do assert_difference('IssueRelation.count', -1) do - delete '/relations/2.xml', {}, credentials('jsmith') + delete '/relations/2.xml', :headers => credentials('jsmith') end assert_response :ok diff --git a/test/integration/api_test/issues_test.rb b/test/integration/api_test/issues_test.rb index 81f62ea2d..649f8c27d 100644 --- a/test/integration/api_test/issues_test.rb +++ b/test/integration/api_test/issues_test.rb @@ -55,7 +55,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base end test "GET /issues.xml with nometa header should not contain metadata" do - get '/issues.xml', {}, {'X-Redmine-Nometa' => '1'} + get '/issues.xml', :headers => {'X-Redmine-Nometa' => '1'} assert_select 'issues[type=array]:not([total_count]):not([limit]):not([offset])' end @@ -99,7 +99,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base end test "GET /issues.xml with invalid query params" do - get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}} + get '/issues.xml', :params => {:f => ['start_date'], :op => {:start_date => '='}} assert_response :unprocessable_entity assert_equal 'application/xml', @response.content_type @@ -108,7 +108,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base test "GET /issues.xml with custom field filter" do get '/issues.xml', - {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}} + :params => {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}} expected_ids = Issue.visible. joins(:custom_values). @@ -121,7 +121,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base end test "GET /issues.xml with custom field filter (shorthand method)" do - get '/issues.xml', {:cf_1 => 'MySQL'} + get '/issues.xml', :params => {:cf_1 => 'MySQL'} expected_ids = Issue.visible. joins(:custom_values). @@ -143,21 +143,24 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base Issue.generate!(:subject => '1').update_column(:updated_on, Time.parse("2014-01-02T10:25:00Z")) Issue.generate!(:subject => '2').update_column(:updated_on, Time.parse("2014-01-02T12:13:00Z")) - get '/issues.xml', - {:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '<='}, - :v => {:updated_on => ['2014-01-02T12:00:00Z']}} + get '/issues.xml', :params => { + :set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '<='}, + :v => {:updated_on => ['2014-01-02T12:00:00Z']} + } assert_select 'issues>issue', :count => 1 assert_select 'issues>issue>subject', :text => '1' - get '/issues.xml', - {:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='}, - :v => {:updated_on => ['2014-01-02T12:00:00Z']}} + get '/issues.xml', :params => { + :set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='}, + :v => {:updated_on => ['2014-01-02T12:00:00Z']} + } assert_select 'issues>issue', :count => 1 assert_select 'issues>issue>subject', :text => '2' - get '/issues.xml', - {:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='}, - :v => {:updated_on => ['2014-01-02T08:00:00Z']}} + get '/issues.xml', :params => { + :set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='}, + :v => {:updated_on => ['2014-01-02T08:00:00Z']} + } assert_select 'issues>issue', :count => 2 end @@ -184,7 +187,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base test "GET /issues/:id.xml with journals" do Journal.find(2).update_attribute(:private_notes, true) - get '/issues/1.xml?include=journals', {}, credentials('jsmith') + get '/issues/1.xml?include=journals', :headers => credentials('jsmith') assert_select 'issue journals[type=array]' do assert_select 'journal[id="1"]' do @@ -353,7 +356,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base test "GET /issues/:id.xml?include=watchers should include watchers" do Watcher.create!(:user_id => 3, :watchable => Issue.find(1)) - get '/issues/1.xml?include=watchers', {}, credentials('jsmith') + get '/issues/1.xml?include=watchers', :headers => credentials('jsmith') assert_response :ok assert_equal 'application/xml', response.content_type @@ -371,7 +374,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base Issue.find(1).changesets << Changeset.generate!(:repository => repository) assert Issue.find(1).changesets.any? - get '/issues/1.xml?include=changesets', {}, credentials('jsmith') + get '/issues/1.xml?include=changesets', :headers => credentials('jsmith') # the user jsmith has no permission to view the associated changeset assert_select 'issue changesets[type=array]' do @@ -422,7 +425,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base TimeEntry.generate!(:user => user, :hours => 5.5, :issue_id => parent.id) TimeEntry.generate!(:user => user, :hours => 2, :issue_id => child.id) TimeEntry.generate!(:user => User.find(1), :hours => 100, :issue_id => child.id) - get '/issues/3.xml', {} , credentials(user.login) + get '/issues/3.xml', :headers => credentials(user.login) assert_equal 'application/xml', response.content_type assert_select 'issue' do @@ -472,7 +475,7 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base TimeEntry.generate!(:user => user, :hours => 5.5, :issue_id => parent.id) TimeEntry.generate!(:user => user, :hours => 2, :issue_id => child.id) TimeEntry.generate!(:user => User.find(1), :hours => 100, :issue_id => child.id) - get '/issues/3.json', {} , credentials(user.login) + get '/issues/3.json', :headers => credentials(user.login) assert_equal 'application/json', response.content_type json = ActiveSupport::JSON.decode(response.body) @@ -493,7 +496,9 @@ payload = <<-XML XML assert_difference('Issue.count') do - post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')) + post '/issues.xml', + :params => payload, + :headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')) end issue = Issue.order('id DESC').first assert_equal 1, issue.project_id @@ -509,8 +514,13 @@ XML test "POST /issues.xml with watcher_user_ids should create issue with watchers" do assert_difference('Issue.count') do post '/issues.xml', - {:issue => {:project_id => 1, :subject => 'Watchers', - :tracker_id => 2, :status_id => 3, :watcher_user_ids => [3, 1]}}, credentials('jsmith') + :params => { + :issue => { + :project_id => 1, :subject => 'Watchers', + :tracker_id => 2, :status_id => 3, :watcher_user_ids => [3, 1] + } + }, + :headers => credentials('jsmith') assert_response :created end issue = Issue.order('id desc').first @@ -520,7 +530,9 @@ XML test "POST /issues.xml with failure should return errors" do assert_no_difference('Issue.count') do - post '/issues.xml', {:issue => {:project_id => 1}}, credentials('jsmith') + post '/issues.xml', + :params => {:issue => {:project_id => 1}}, + :headers => credentials('jsmith') end assert_select 'errors error', :text => "Subject cannot be blank" @@ -540,7 +552,9 @@ payload = <<-JSON JSON assert_difference('Issue.count') do - post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) + post '/issues.json', + :params => payload, + :headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) end issue = Issue.order('id DESC').first @@ -553,8 +567,8 @@ JSON test "POST /issues.json should accept project identifier as project_id" do assert_difference('Issue.count') do post '/issues.json', - {:issue => {:project_id => 'subproject1', :tracker_id => 2, :subject => 'Foo'}}, - credentials('jsmith') + :params => {:issue => {:project_id => 'subproject1', :tracker_id => 2, :subject => 'Foo'}}, + :headers => credentials('jsmith') assert_response :created end @@ -581,7 +595,9 @@ payload = <<-JSON JSON assert_difference('Issue.count') do - post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) + post '/issues.json', + :params => payload, + :headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) end assert_response :created @@ -594,8 +610,8 @@ JSON issue = new_record(Issue) do post '/issues.json', - {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {}}}, - credentials('jsmith') + :params => {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {}}}, + :headers => credentials('jsmith') end assert_equal "Default", issue.custom_field_value(field) end @@ -605,15 +621,17 @@ JSON issue = new_record(Issue) do post '/issues.json', - {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {field.id.to_s => ""}}}, - credentials('jsmith') + :params => {:issue => {:project_id => 1, :subject => 'API', :custom_field_values => {field.id.to_s => ""}}}, + :headers => credentials('jsmith') end assert_equal "", issue.custom_field_value(field) end test "POST /issues.json with failure should return errors" do assert_no_difference('Issue.count') do - post '/issues.json', {:issue => {:project_id => 1}}, credentials('jsmith') + post '/issues.json', + :params => {:issue => {:project_id => 1}}, + :headers => credentials('jsmith') end json = ActiveSupport::JSON.decode(response.body) @@ -621,15 +639,17 @@ JSON end test "POST /issues.json with invalid project_id should respond with 422" do - post '/issues.json', {:issue => {:project_id => 999, :subject => "API"}}, credentials('jsmith') + post '/issues.json', + :params => {:issue => {:project_id => 999, :subject => "API"}}, + :headers => credentials('jsmith') assert_response 422 end test "PUT /issues/:id.xml" do assert_difference('Journal.count') do put '/issues/6.xml', - {:issue => {:subject => 'API update', :notes => 'A new note'}}, - credentials('jsmith') + :params => {:issue => {:subject => 'API update', :notes => 'A new note'}}, + :headers => credentials('jsmith') end issue = Issue.find(6) @@ -640,11 +660,12 @@ JSON test "PUT /issues/:id.xml with custom fields" do put '/issues/3.xml', - {:issue => {:custom_fields => [ + :params => {:issue => {:custom_fields => [ {'id' => '1', 'value' => 'PostgreSQL' }, {'id' => '2', 'value' => '150'} - ]}}, - credentials('jsmith') + ]} + }, + :headers => credentials('jsmith') issue = Issue.find(3) assert_equal '150', issue.custom_value_for(2).value @@ -656,11 +677,12 @@ JSON field.update_attribute :multiple, true put '/issues/3.xml', - {:issue => {:custom_fields => [ + :params => {:issue => {:custom_fields => [ {'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] }, {'id' => '2', 'value' => '150'} - ]}}, - credentials('jsmith') + ]} + }, + :headers => credentials('jsmith') issue = Issue.find(3) assert_equal '150', issue.custom_value_for(2).value @@ -669,8 +691,8 @@ JSON test "PUT /issues/:id.xml with project change" do put '/issues/3.xml', - {:issue => {:project_id => 2, :subject => 'Project changed'}}, - credentials('jsmith') + :params => {:issue => {:project_id => 2, :subject => 'Project changed'}}, + :headers => credentials('jsmith') issue = Issue.find(3) assert_equal 2, issue.project_id @@ -680,8 +702,8 @@ JSON test "PUT /issues/:id.xml with notes only" do assert_difference('Journal.count') do put '/issues/6.xml', - {:issue => {:notes => 'Notes only'}}, - credentials('jsmith') + :params => {:issue => {:notes => 'Notes only'}}, + :headers => credentials('jsmith') end journal = Journal.last @@ -695,8 +717,8 @@ JSON assert_difference('Journal.count') do put "/issues/#{issue.id}.json", - {:issue => {:custom_field_values => {}, :notes => 'API'}}, - credentials('jsmith') + :params => {:issue => {:custom_field_values => {}, :notes => 'API'}}, + :headers => credentials('jsmith') end assert_equal "", issue.reload.custom_field_value(field) @@ -709,8 +731,8 @@ JSON assert_difference('Journal.count') do put "/issues/#{issue.id}.json", - {:issue => {:custom_field_values => {field.id.to_s => ""}, :notes => 'API'}}, - credentials('jsmith') + :params => {:issue => {:custom_field_values => {field.id.to_s => ""}, :notes => 'API'}}, + :headers => credentials('jsmith') end assert_equal "", issue.reload.custom_field_value(field) @@ -722,8 +744,8 @@ JSON assert_difference('Journal.count') do put "/issues/#{issue.id}.json", - {:issue => {:tracker_id => 2, :custom_field_values => {}, :notes => 'API'}}, - credentials('jsmith') + :params => {:issue => {:tracker_id => 2, :custom_field_values => {}, :notes => 'API'}}, + :headers => credentials('jsmith') end assert_equal 2, issue.reload.tracker_id @@ -736,8 +758,8 @@ JSON assert_difference('Journal.count') do put "/issues/#{issue.id}.json", - {:issue => {:tracker_id => 2, :custom_field_values => {field.id.to_s => ""}, :notes => 'API'}}, - credentials('jsmith') + :params => {:issue => {:tracker_id => 2, :custom_field_values => {field.id.to_s => ""}, :notes => 'API'}}, + :headers => credentials('jsmith') end assert_equal 2, issue.reload.tracker_id @@ -745,7 +767,9 @@ JSON end test "PUT /issues/:id.xml with failed update" do - put '/issues/6.xml', {:issue => {:subject => ''}}, credentials('jsmith') + put '/issues/6.xml', + :params => {:issue => {:subject => ''}}, + :headers => credentials('jsmith') assert_response :unprocessable_entity assert_select 'errors error', :text => "Subject cannot be blank" @@ -753,7 +777,9 @@ JSON test "PUT /issues/:id.xml with invalid assignee should return error" do user = User.generate! - put '/issues/6.xml', {:issue => {:assigned_to_id => user.id}}, credentials('jsmith') + put '/issues/6.xml', + :params => {:issue => {:assigned_to_id => user.id}}, + :headers => credentials('jsmith') assert_response :unprocessable_entity assert_select 'errors error', :text => "Assignee is invalid" @@ -762,8 +788,8 @@ JSON test "PUT /issues/:id.json" do assert_difference('Journal.count') do put '/issues/6.json', - {:issue => {:subject => 'API update', :notes => 'A new note'}}, - credentials('jsmith') + :params => {:issue => {:subject => 'API update', :notes => 'A new note'}}, + :headers => credentials('jsmith') assert_response :ok assert_equal '', response.body @@ -776,7 +802,9 @@ JSON end test "PUT /issues/:id.json with failed update" do - put '/issues/6.json', {:issue => {:subject => ''}}, credentials('jsmith') + put '/issues/6.json', + :params => {:issue => {:subject => ''}}, + :headers => credentials('jsmith') assert_response :unprocessable_entity json = ActiveSupport::JSON.decode(response.body) @@ -785,7 +813,7 @@ JSON test "DELETE /issues/:id.xml" do assert_difference('Issue.count', -1) do - delete '/issues/6.xml', {}, credentials('jsmith') + delete '/issues/6.xml', :headers => credentials('jsmith') assert_response :ok assert_equal '', response.body @@ -795,7 +823,7 @@ JSON test "DELETE /issues/:id.json" do assert_difference('Issue.count', -1) do - delete '/issues/6.json', {}, credentials('jsmith') + delete '/issues/6.json', :headers => credentials('jsmith') assert_response :ok assert_equal '', response.body @@ -805,7 +833,9 @@ JSON test "POST /issues/:id/watchers.xml should add watcher" do assert_difference 'Watcher.count' do - post '/issues/1/watchers.xml', {:user_id => 3}, credentials('jsmith') + post '/issues/1/watchers.xml', + :params => {:user_id => 3}, + :headers => credentials('jsmith') assert_response :ok assert_equal '', response.body @@ -819,7 +849,7 @@ JSON Watcher.create!(:user_id => 3, :watchable => Issue.find(1)) assert_difference 'Watcher.count', -1 do - delete '/issues/1/watchers/3.xml', {}, credentials('jsmith') + delete '/issues/1/watchers/3.xml', :headers => credentials('jsmith') assert_response :ok assert_equal '', response.body @@ -834,10 +864,10 @@ JSON # create the issue with the upload's token assert_difference 'Issue.count' do post '/issues.xml', - {:issue => {:project_id => 1, :subject => 'Uploaded file', + :params => {:issue => {:project_id => 1, :subject => 'Uploaded file', :uploads => [{:token => token, :filename => 'test.txt', :content_type => 'text/plain'}]}}, - credentials('jsmith') + :headers => credentials('jsmith') assert_response :created end issue = Issue.order('id DESC').first @@ -851,7 +881,7 @@ JSON assert_equal 2, attachment.author_id # get the issue with its attachments - get "/issues/#{issue.id}.xml", :include => 'attachments' + get "/issues/#{issue.id}.xml?include=attachments" assert_response :success xml = Hash.from_xml(response.body) attachments = xml['issue']['attachments'] @@ -890,7 +920,9 @@ JSON XML assert_difference 'Issue.count' do - post '/issues.xml', payload, {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')) + post '/issues.xml', + :params => payload, + :headers => {"CONTENT_TYPE" => 'application/xml'}.merge(credentials('jsmith')) assert_response :created end issue = Issue.order('id DESC').first @@ -916,7 +948,9 @@ XML JSON assert_difference 'Issue.count' do - post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) + post '/issues.json', + :params => payload, + :headers => {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) assert_response :created end issue = Issue.order('id DESC').first @@ -930,10 +964,10 @@ JSON # update the issue with the upload's token assert_difference 'Journal.count' do put '/issues/1.xml', - {:issue => {:notes => 'Attachment added', + :params => {:issue => {:notes => 'Attachment added', :uploads => [{:token => token, :filename => 'test.txt', :content_type => 'text/plain'}]}}, - credentials('jsmith') + :headers => credentials('jsmith') assert_response :ok assert_equal '', @response.body end diff --git a/test/integration/api_test/memberships_test.rb b/test/integration/api_test/memberships_test.rb index dd259839d..3324b2f33 100644 --- a/test/integration/api_test/memberships_test.rb +++ b/test/integration/api_test/memberships_test.rb @@ -21,7 +21,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base fixtures :projects, :users, :roles, :members, :member_roles test "GET /projects/:project_id/memberships.xml should return memberships" do - get '/projects/1/memberships.xml', {}, credentials('jsmith') + get '/projects/1/memberships.xml', :headers => credentials('jsmith') assert_response :success assert_equal 'application/xml', @response.content_type @@ -32,7 +32,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base end test "GET /projects/:project_id/memberships.json should return memberships" do - get '/projects/1/memberships.json', {}, credentials('jsmith') + get '/projects/1/memberships.json', :headers => credentials('jsmith') assert_response :success assert_equal 'application/json', @response.content_type @@ -54,13 +54,13 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base project = Project.find(1) project.close assert !project.reload.active? - get '/projects/1/memberships.json', {}, credentials('jsmith') + get '/projects/1/memberships.json', :headers => credentials('jsmith') assert_response :success end test "GET /projects/:project_id/memberships.xml should include locked users" do assert User.find(3).lock! - get '/projects/ecookbook/memberships.xml', {}, credentials('jsmith') + get '/projects/ecookbook/memberships.xml', :headers => credentials('jsmith') assert_response :success assert_select 'memberships[type=array] membership id', :text => '2' do assert_select '~ user[id="3"][name="Dave Lopper"]' @@ -69,7 +69,9 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base test "POST /projects/:project_id/memberships.xml should create the membership" do assert_difference 'Member.count' do - post '/projects/1/memberships.xml', {:membership => {:user_id => 7, :role_ids => [2,3]}}, credentials('jsmith') + post '/projects/1/memberships.xml', + :params => {:membership => {:user_id => 7, :role_ids => [2,3]}}, + :headers => credentials('jsmith') assert_response :created end @@ -79,7 +81,9 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base group = Group.find(11) assert_difference 'Member.count', 1 + group.users.count do - post '/projects/1/memberships.xml', {:membership => {:user_id => 11, :role_ids => [2,3]}}, credentials('jsmith') + post '/projects/1/memberships.xml', + :params => {:membership => {:user_id => 11, :role_ids => [2,3]}}, + :headers => credentials('jsmith') assert_response :created end @@ -87,7 +91,9 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base test "POST /projects/:project_id/memberships.xml with invalid parameters should return errors" do assert_no_difference 'Member.count' do - post '/projects/1/memberships.xml', {:membership => {:role_ids => [2,3]}}, credentials('jsmith') + post '/projects/1/memberships.xml', + :params => {:membership => {:role_ids => [2,3]}}, + :headers => credentials('jsmith') assert_response :unprocessable_entity assert_equal 'application/xml', @response.content_type @@ -96,7 +102,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base end test "GET /memberships/:id.xml should return the membership" do - get '/memberships/2.xml', {}, credentials('jsmith') + get '/memberships/2.xml', :headers => credentials('jsmith') assert_response :success assert_equal 'application/xml', @response.content_type @@ -107,7 +113,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base end test "GET /memberships/:id.json should return the membership" do - get '/memberships/2.json', {}, credentials('jsmith') + get '/memberships/2.json', :headers => credentials('jsmith') assert_response :success assert_equal 'application/json', @response.content_type @@ -125,7 +131,9 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base test "PUT /memberships/:id.xml should update the membership" do assert_not_equal [1,2], Member.find(2).role_ids.sort assert_no_difference 'Member.count' do - put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [1,2]}}, credentials('jsmith') + put '/memberships/2.xml', + :params => {:membership => {:user_id => 3, :role_ids => [1,2]}}, + :headers => credentials('jsmith') assert_response :ok assert_equal '', @response.body @@ -135,7 +143,9 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base end test "PUT /memberships/:id.xml with invalid parameters should return errors" do - put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [99]}}, credentials('jsmith') + put '/memberships/2.xml', + :params => {:membership => {:user_id => 3, :role_ids => [99]}}, + :headers => credentials('jsmith') assert_response :unprocessable_entity assert_equal 'application/xml', @response.content_type @@ -144,7 +154,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base test "DELETE /memberships/:id.xml should destroy the membership" do assert_difference 'Member.count', -1 do - delete '/memberships/2.xml', {}, credentials('jsmith') + delete '/memberships/2.xml', :headers => credentials('jsmith') assert_response :ok assert_equal '', @response.body @@ -156,7 +166,7 @@ class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base assert_no_difference 'Member.count' do # A membership with an inherited role cannot be deleted Member.find(2).member_roles.first.update_attribute :inherited_from, 99 - delete '/memberships/2.xml', {}, credentials('jsmith') + delete '/memberships/2.xml', :headers => credentials('jsmith') assert_response :unprocessable_entity end diff --git a/test/integration/api_test/projects_test.rb b/test/integration/api_test/projects_test.rb index 7b9c58a13..d5d452930 100644 --- a/test/integration/api_test/projects_test.rb +++ b/test/integration/api_test/projects_test.rb @@ -142,8 +142,8 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base with_settings :default_projects_modules => ['issue_tracking', 'repository'] do assert_difference('Project.count') do post '/projects.xml', - {:project => {:name => 'API test', :identifier => 'api-test'}}, - credentials('admin') + :params => {:project => {:name => 'API test', :identifier => 'api-test'}}, + :headers => credentials('admin') end end @@ -161,8 +161,8 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base test "POST /projects.xml should accept enabled_module_names attribute" do assert_difference('Project.count') do post '/projects.xml', - {:project => {:name => 'API test', :identifier => 'api-test', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}}, - credentials('admin') + :params => {:project => {:name => 'API test', :identifier => 'api-test', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}}, + :headers => credentials('admin') end project = Project.order('id DESC').first @@ -172,8 +172,8 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base test "POST /projects.xml should accept tracker_ids attribute" do assert_difference('Project.count') do post '/projects.xml', - {:project => {:name => 'API test', :identifier => 'api-test', :tracker_ids => [1, 3]}}, - credentials('admin') + :params => {:project => {:name => 'API test', :identifier => 'api-test', :tracker_ids => [1, 3]}}, + :headers => credentials('admin') end project = Project.order('id DESC').first @@ -182,7 +182,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base test "POST /projects.xml with invalid parameters should return errors" do assert_no_difference('Project.count') do - post '/projects.xml', {:project => {:name => 'API test'}}, credentials('admin') + post '/projects.xml', + :params => {:project => {:name => 'API test'}}, + :headers => credentials('admin') end assert_response :unprocessable_entity @@ -192,7 +194,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base test "PUT /projects/:id.xml with valid parameters should update the project" do assert_no_difference 'Project.count' do - put '/projects/2.xml', {:project => {:name => 'API update'}}, credentials('jsmith') + put '/projects/2.xml', + :params => {:project => {:name => 'API update'}}, + :headers => credentials('jsmith') end assert_response :ok assert_equal '', @response.body @@ -203,7 +207,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base test "PUT /projects/:id.xml should accept enabled_module_names attribute" do assert_no_difference 'Project.count' do - put '/projects/2.xml', {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}}, credentials('admin') + put '/projects/2.xml', + :params => {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}}, + :headers => credentials('admin') end assert_response :ok assert_equal '', @response.body @@ -213,7 +219,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base test "PUT /projects/:id.xml should accept tracker_ids attribute" do assert_no_difference 'Project.count' do - put '/projects/2.xml', {:project => {:name => 'API update', :tracker_ids => [1, 3]}}, credentials('admin') + put '/projects/2.xml', + :params => {:project => {:name => 'API update', :tracker_ids => [1, 3]}}, + :headers => credentials('admin') end assert_response :ok assert_equal '', @response.body @@ -223,7 +231,9 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base test "PUT /projects/:id.xml with invalid parameters should return errors" do assert_no_difference('Project.count') do - put '/projects/2.xml', {:project => {:name => ''}}, credentials('admin') + put '/projects/2.xml', + :params => {:project => {:name => ''}}, + :headers => credentials('admin') end assert_response :unprocessable_entity @@ -233,7 +243,7 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base test "DELETE /projects/:id.xml should delete the project" do assert_difference('Project.count',-1) do - delete '/projects/2.xml', {}, credentials('admin') + delete '/projects/2.xml', :headers => credentials('admin') end assert_response :ok assert_equal '', @response.body diff --git a/test/integration/api_test/search_test.rb b/test/integration/api_test/search_test.rb index f09a447a0..6589c6db1 100644 --- a/test/integration/api_test/search_test.rb +++ b/test/integration/api_test/search_test.rb @@ -45,7 +45,7 @@ class Redmine::ApiTest::SearchTest < Redmine::ApiTest::Base end test "GET /search.xml without query strings should return empty results" do - get '/search.xml', :q => '', :all_words => '' + get '/search.xml', :params => {:q => '', :all_words => ''} assert_response :success assert_select 'result', 0 @@ -54,7 +54,7 @@ class Redmine::ApiTest::SearchTest < Redmine::ApiTest::Base test "GET /search.xml with query strings should return results" do issue = Issue.generate!(:subject => 'searchapi') - get '/search.xml', :q => 'searchapi', :all_words => '' + get '/search.xml', :params => {:q => 'searchapi', :all_words => ''} assert_response :success @@ -75,14 +75,14 @@ class Redmine::ApiTest::SearchTest < Redmine::ApiTest::Base test "GET /search.xml should paginate" do issue = (0..10).map {Issue.generate! :subject => 'search_with_limited_results'}.reverse.map(&:id) - get '/search.json', :q => 'search_with_limited_results', :limit => 4 + get '/search.json', :params => {:q => 'search_with_limited_results', :limit => 4} json = ActiveSupport::JSON.decode(response.body) assert_equal 11, json['total_count'] assert_equal 0, json['offset'] assert_equal 4, json['limit'] assert_equal issue[0..3], json['results'].map {|r| r['id']} - get '/search.json', :q => 'search_with_limited_results', :offset => 8, :limit => 4 + get '/search.json', :params => {:q => 'search_with_limited_results', :offset => 8, :limit => 4} json = ActiveSupport::JSON.decode(response.body) assert_equal 11, json['total_count'] assert_equal 8, json['offset'] diff --git a/test/integration/api_test/time_entries_test.rb b/test/integration/api_test/time_entries_test.rb index 546f19a19..6ac2fa7af 100644 --- a/test/integration/api_test/time_entries_test.rb +++ b/test/integration/api_test/time_entries_test.rb @@ -28,21 +28,21 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base :time_entries test "GET /time_entries.xml should return time entries" do - get '/time_entries.xml', {}, credentials('jsmith') + get '/time_entries.xml', :headers => credentials('jsmith') assert_response :success assert_equal 'application/xml', @response.content_type assert_select 'time_entries[type=array] time_entry id', :text => '2' end test "GET /time_entries.xml with limit should return limited results" do - get '/time_entries.xml?limit=2', {}, credentials('jsmith') + get '/time_entries.xml?limit=2', :headers => credentials('jsmith') assert_response :success assert_equal 'application/xml', @response.content_type assert_select 'time_entries[type=array] time_entry', 2 end test "GET /time_entries/:id.xml should return the time entry" do - get '/time_entries/2.xml', {}, credentials('jsmith') + get '/time_entries/2.xml', :headers => credentials('jsmith') assert_response :success assert_equal 'application/xml', @response.content_type assert_select 'time_entry id', :text => '2' @@ -53,7 +53,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base project.close project.save! - get '/time_entries/2.xml', {}, credentials('jsmith') + get '/time_entries/2.xml', :headers => credentials('jsmith') assert_response :success assert_equal 'application/xml', @response.content_type assert_select 'time_entry id', :text => '2' @@ -61,7 +61,9 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base test "POST /time_entries.xml with issue_id should create time entry" do assert_difference 'TimeEntry.count' do - post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') + post '/time_entries.xml', + :params => {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, + :headers => credentials('jsmith') end assert_response :created assert_equal 'application/xml', @response.content_type @@ -79,9 +81,11 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string') assert_difference 'TimeEntry.count' do - post '/time_entries.xml', {:time_entry => { - :issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}] - }}, credentials('jsmith') + post '/time_entries.xml', + :params => {:time_entry => { + :issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}] + }}, + :headers => credentials('jsmith') end assert_response :created assert_equal 'application/xml', @response.content_type @@ -92,7 +96,9 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base test "POST /time_entries.xml with project_id should create time entry" do assert_difference 'TimeEntry.count' do - post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') + post '/time_entries.xml', + :params => {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, + :headers => credentials('jsmith') end assert_response :created assert_equal 'application/xml', @response.content_type @@ -108,7 +114,9 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base test "POST /time_entries.xml with invalid parameters should return errors" do assert_no_difference 'TimeEntry.count' do - post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith') + post '/time_entries.xml', + :params => {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, + :headers => credentials('jsmith') end assert_response :unprocessable_entity assert_equal 'application/xml', @response.content_type @@ -118,7 +126,9 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base test "PUT /time_entries/:id.xml with valid parameters should update time entry" do assert_no_difference 'TimeEntry.count' do - put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith') + put '/time_entries/2.xml', + :params => {:time_entry => {:comments => 'API Update'}}, + :headers => credentials('jsmith') end assert_response :ok assert_equal '', @response.body @@ -127,7 +137,9 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base test "PUT /time_entries/:id.xml with invalid parameters should return errors" do assert_no_difference 'TimeEntry.count' do - put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith') + put '/time_entries/2.xml', + :params => {:time_entry => {:hours => '', :comments => 'API Update'}}, + :headers => credentials('jsmith') end assert_response :unprocessable_entity assert_equal 'application/xml', @response.content_type @@ -137,7 +149,7 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base test "DELETE /time_entries/:id.xml should destroy time entry" do assert_difference 'TimeEntry.count', -1 do - delete '/time_entries/2.xml', {}, credentials('jsmith') + delete '/time_entries/2.xml', :headers => credentials('jsmith') end assert_response :ok assert_equal '', @response.body diff --git a/test/integration/api_test/users_test.rb b/test/integration/api_test/users_test.rb index 9118a8b9c..53209f72f 100644 --- a/test/integration/api_test/users_test.rb +++ b/test/integration/api_test/users_test.rb @@ -21,7 +21,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base fixtures :users, :email_addresses, :members, :member_roles, :roles, :projects test "GET /users.xml should return users" do - get '/users.xml', {}, credentials('admin') + get '/users.xml', :headers => credentials('admin') assert_response :success assert_equal 'application/xml', response.content_type @@ -31,7 +31,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base end test "GET /users.json should return users" do - get '/users.json', {}, credentials('admin') + get '/users.json', :headers => credentials('admin') assert_response :success assert_equal 'application/json', response.content_type @@ -84,56 +84,58 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base end test "GET /users/current.xml should return current user" do - get '/users/current.xml', {}, credentials('jsmith') + get '/users/current.xml', :headers => credentials('jsmith') assert_select 'user id', :text => '2' end test "GET /users/:id should not return login for other user" do - get '/users/3.xml', {}, credentials('jsmith') + get '/users/3.xml', :headers => credentials('jsmith') assert_response :success assert_select 'user login', 0 end test "GET /users/:id should return login for current user" do - get '/users/2.xml', {}, credentials('jsmith') + get '/users/2.xml', :headers => credentials('jsmith') assert_response :success assert_select 'user login', :text => 'jsmith' end test "GET /users/:id should not return api_key for other user" do - get '/users/3.xml', {}, credentials('jsmith') + get '/users/3.xml', :headers => credentials('jsmith') assert_response :success assert_select 'user api_key', 0 end test "GET /users/:id should return api_key for current user" do - get '/users/2.xml', {}, credentials('jsmith') + get '/users/2.xml', :headers => credentials('jsmith') assert_response :success assert_select 'user api_key', :text => User.find(2).api_key end test "GET /users/:id should not return status for standard user" do - get '/users/3.xml', {}, credentials('jsmith') + get '/users/3.xml', :headers => credentials('jsmith') assert_response :success assert_select 'user status', 0 end test "GET /users/:id should return status for administrators" do - get '/users/2.xml', {}, credentials('admin') + get '/users/2.xml', :headers => credentials('admin') assert_response :success assert_select 'user status', :text => User.find(1).status.to_s end test "POST /users.xml with valid parameters should create the user" do assert_difference('User.count') do - post '/users.xml', { - :user => { - :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', - :mail => 'foo@example.net', :password => 'secret123', - :mail_notification => 'only_assigned'} + post '/users.xml', + :params => { + :user => { + :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', + :mail => 'foo@example.net', :password => 'secret123', + :mail_notification => 'only_assigned' + } }, - credentials('admin') + :headers => credentials('admin') end user = User.order('id DESC').first @@ -152,13 +154,15 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base test "POST /users.json with valid parameters should create the user" do assert_difference('User.count') do - post '/users.json', { - :user => { - :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', - :mail => 'foo@example.net', :password => 'secret123', - :mail_notification => 'only_assigned'} + post '/users.json', + :params => { + :user => { + :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname', + :mail => 'foo@example.net', :password => 'secret123', + :mail_notification => 'only_assigned' + } }, - credentials('admin') + :headers => credentials('admin') end user = User.order('id DESC').first @@ -178,7 +182,13 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base test "POST /users.xml with with invalid parameters should return errors" do assert_no_difference('User.count') do - post '/users.xml', {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}, credentials('admin') + post '/users.xml', + :params => { + :user =>{ + :login => 'foo', :lastname => 'Lastname', :mail => 'foo' + } + }, + :headers => credentials('admin') end assert_response :unprocessable_entity @@ -188,7 +198,13 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base test "POST /users.json with with invalid parameters should return errors" do assert_no_difference('User.count') do - post '/users.json', {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}, credentials('admin') + post '/users.json', + :params => { + :user => { + :login => 'foo', :lastname => 'Lastname', :mail => 'foo' + } + }, + :headers => credentials('admin') end assert_response :unprocessable_entity @@ -201,12 +217,14 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base test "PUT /users/:id.xml with valid parameters should update the user" do assert_no_difference('User.count') do - put '/users/2.xml', { - :user => { - :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', - :mail => 'jsmith@somenet.foo'} + put '/users/2.xml', + :params => { + :user => { + :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', + :mail => 'jsmith@somenet.foo' + } }, - credentials('admin') + :headers => credentials('admin') end user = User.find(2) @@ -222,12 +240,14 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base test "PUT /users/:id.json with valid parameters should update the user" do assert_no_difference('User.count') do - put '/users/2.json', { - :user => { - :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', - :mail => 'jsmith@somenet.foo'} + put '/users/2.json', + :params => { + :user => { + :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed', + :mail => 'jsmith@somenet.foo' + } }, - credentials('admin') + :headers => credentials('admin') end user = User.find(2) @@ -243,12 +263,14 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base test "PUT /users/:id.xml with invalid parameters" do assert_no_difference('User.count') do - put '/users/2.xml', { - :user => { - :login => 'jsmith', :firstname => '', :lastname => 'Lastname', - :mail => 'foo'} + put '/users/2.xml', + :params => { + :user => { + :login => 'jsmith', :firstname => '', :lastname => 'Lastname', + :mail => 'foo' + } }, - credentials('admin') + :headers => credentials('admin') end assert_response :unprocessable_entity @@ -258,12 +280,14 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base test "PUT /users/:id.json with invalid parameters" do assert_no_difference('User.count') do - put '/users/2.json', { - :user => { - :login => 'jsmith', :firstname => '', :lastname => 'Lastname', - :mail => 'foo'} + put '/users/2.json', + :params => { + :user => { + :login => 'jsmith', :firstname => '', :lastname => 'Lastname', + :mail => 'foo' + } }, - credentials('admin') + :headers => credentials('admin') end assert_response :unprocessable_entity @@ -276,7 +300,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base test "DELETE /users/:id.xml should delete the user" do assert_difference('User.count', -1) do - delete '/users/2.xml', {}, credentials('admin') + delete '/users/2.xml', :headers => credentials('admin') end assert_response :ok @@ -285,7 +309,7 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base test "DELETE /users/:id.json should delete the user" do assert_difference('User.count', -1) do - delete '/users/2.json', {}, credentials('admin') + delete '/users/2.json', :headers => credentials('admin') end assert_response :ok diff --git a/test/integration/api_test/versions_test.rb b/test/integration/api_test/versions_test.rb index 6093237d5..70fae0210 100644 --- a/test/integration/api_test/versions_test.rb +++ b/test/integration/api_test/versions_test.rb @@ -40,7 +40,9 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base test "POST /projects/:project_id/versions.xml should create the version" do assert_difference 'Version.count' do - post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith') + post '/projects/1/versions.xml', + :params => {:version => {:name => 'API test'}}, + :headers => credentials('jsmith') end version = Version.order('id DESC').first @@ -53,7 +55,9 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base test "POST /projects/:project_id/versions.xml should create the version with due date" do assert_difference 'Version.count' do - post '/projects/1/versions.xml', {:version => {:name => 'API test', :due_date => '2012-01-24'}}, credentials('jsmith') + post '/projects/1/versions.xml', + :params => {:version => {:name => 'API test', :due_date => '2012-01-24'}}, + :headers => credentials('jsmith') end version = Version.order('id DESC').first @@ -69,14 +73,16 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base field = VersionCustomField.generate! assert_difference 'Version.count' do - post '/projects/1/versions.xml', { + post '/projects/1/versions.xml', + :params => { :version => { :name => 'API test', :custom_fields => [ {'id' => field.id.to_s, 'value' => 'Some value'} ] } - }, credentials('jsmith') + }, + :headers => credentials('jsmith') end version = Version.order('id DESC').first @@ -90,7 +96,9 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base test "POST /projects/:project_id/versions.xml with failure should return the errors" do assert_no_difference('Version.count') do - post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith') + post '/projects/1/versions.xml', + :params => {:version => {:name => ''}}, + :headers => credentials('jsmith') end assert_response :unprocessable_entity @@ -110,7 +118,9 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base end test "PUT /versions/:id.xml should update the version" do - put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith') + put '/versions/2.xml', + :params => {:version => {:name => 'API update'}}, + :headers => credentials('jsmith') assert_response :ok assert_equal '', @response.body @@ -119,7 +129,7 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base test "DELETE /versions/:id.xml should destroy the version" do assert_difference 'Version.count', -1 do - delete '/versions/3.xml', {}, credentials('jsmith') + delete '/versions/3.xml', :headers => credentials('jsmith') end assert_response :ok diff --git a/test/integration/api_test/wiki_pages_test.rb b/test/integration/api_test/wiki_pages_test.rb index 51e132eda..2f9b024f9 100644 --- a/test/integration/api_test/wiki_pages_test.rb +++ b/test/integration/api_test/wiki_pages_test.rb @@ -72,7 +72,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base end test "GET /projects/:project_id/wiki/:title.xml with unknown title and edit permission should respond with 404" do - get '/projects/ecookbook/wiki/Invalid_Page.xml', {}, credentials('jsmith') + get '/projects/ecookbook/wiki/Invalid_Page.xml', :headers => credentials('jsmith') assert_response 404 assert_equal 'application/xml', response.content_type end @@ -104,8 +104,8 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base assert_no_difference 'WikiPage.count' do assert_difference 'WikiContent::Version.count' do put '/projects/ecookbook/wiki/CookBook_documentation.xml', - {:wiki_page => {:text => 'New content from API', :comments => 'API update'}}, - credentials('jsmith') + :params => {:wiki_page => {:text => 'New content from API', :comments => 'API update'}}, + :headers => credentials('jsmith') assert_response 200 end end @@ -121,8 +121,8 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base assert_no_difference 'WikiPage.count' do assert_difference 'WikiContent::Version.count' do put '/projects/ecookbook/wiki/CookBook_documentation.xml', - {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}}, - credentials('jsmith') + :params => {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}}, + :headers => credentials('jsmith') assert_response 200 end end @@ -138,8 +138,8 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base assert_no_difference 'WikiPage.count' do assert_no_difference 'WikiContent::Version.count' do put '/projects/ecookbook/wiki/CookBook_documentation.xml', - {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '2'}}, - credentials('jsmith') + :params => {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '2'}}, + :headers => credentials('jsmith') assert_response 409 end end @@ -149,8 +149,8 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base assert_difference 'WikiPage.count' do assert_difference 'WikiContent::Version.count' do put '/projects/ecookbook/wiki/New_page_from_API.xml', - {:wiki_page => {:text => 'New content from API', :comments => 'API create'}}, - credentials('jsmith') + :params => {:wiki_page => {:text => 'New content from API', :comments => 'API create'}}, + :headers => credentials('jsmith') assert_response 201 end end @@ -170,9 +170,9 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base assert_difference 'WikiPage.count' do assert_difference 'WikiContent::Version.count' do put '/projects/ecookbook/wiki/New_page_from_API.xml', - {:wiki_page => {:text => 'New content from API with Attachments', :comments => 'API create with Attachments', + :params => {:wiki_page => {:text => 'New content from API with Attachments', :comments => 'API create with Attachments', :uploads => [:token => attachment.token, :filename => 'testfile.txt', :content_type => "text/plain"]}}, - credentials('jsmith') + :headers => credentials('jsmith') assert_response 201 end end @@ -187,8 +187,8 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base assert_difference 'WikiPage.count' do assert_difference 'WikiContent::Version.count' do put '/projects/ecookbook/wiki/New_subpage_from_API.xml', - {:wiki_page => {:parent_title => 'CookBook_documentation', :text => 'New content from API', :comments => 'API create'}}, - credentials('jsmith') + :params => {:wiki_page => {:parent_title => 'CookBook_documentation', :text => 'New content from API', :comments => 'API create'}}, + :headers => credentials('jsmith') assert_response 201 end end @@ -200,7 +200,7 @@ class Redmine::ApiTest::WikiPagesTest < Redmine::ApiTest::Base test "DELETE /projects/:project_id/wiki/:title.xml should destroy the page" do assert_difference 'WikiPage.count', -1 do - delete '/projects/ecookbook/wiki/CookBook_documentation.xml', {}, credentials('jsmith') + delete '/projects/ecookbook/wiki/CookBook_documentation.xml', :headers => credentials('jsmith') assert_response 200 end |