test "POST /uploads.xml should return the token" do
set_tmp_attachments_directory
assert_difference 'Attachment.count' do
- post '/uploads.xml', :headers => {
+ 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.media_type
end
test "POST /uploads.json should return the token" do
set_tmp_attachments_directory
assert_difference 'Attachment.count' do
- post '/uploads.json', :headers => {
+ 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.media_type
end
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', :headers => {
+ post(
+ '/uploads.xml?filename=test.txt',
+ :headers => {
"RAW_POST_DATA" => 'File content',
"CONTENT_TYPE" => 'application/octet-stream'
}.merge(credentials('jsmith'))
+ )
assert_response :created
end
test "POST /uploads.xml should not accept other content types" do
set_tmp_attachments_directory
assert_no_difference 'Attachment.count' do
- post '/uploads.xml', :headers => {
+ post(
+ '/uploads.xml',
+ :headers => {
"RAW_POST_DATA" => 'PNG DATA',
"CONTENT_TYPE" => 'image/png'
}.merge(credentials('jsmith'))
+ )
assert_response 406
end
end
set_tmp_attachments_directory
with_settings :attachment_max_size => 1 do
assert_no_difference 'Attachment.count' do
- post '/uploads.xml', :headers => {
+ 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
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', :headers => {
+ post(
+ '/uploads.json',
+ :headers => {
"CONTENT_TYPE" => 'application/octet-stream'
}.merge(credentials('jsmith'))
+ )
assert_response :created
end
json = ActiveSupport::JSON.decode(response.body)