diff options
Diffstat (limited to 'test/integration/api_test/attachments_test.rb')
-rw-r--r-- | test/integration/api_test/attachments_test.rb | 51 |
1 files changed, 34 insertions, 17 deletions
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 |