Adds support for adding attachments to issues through the REST API (#8171).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8928 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2012-02-23 10:01:16 +00:00
parent d086683b17
commit 77626ef6fb
10 changed files with 175 additions and 19 deletions
@@ -82,4 +82,39 @@ class ApiTest::AttachmentsTest < ActionController::IntegrationTest
end
end
end
context "POST /uploads" do
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'))
assert_response :created
assert_equal 'application/xml', response.content_type
xml = Hash.from_xml(response.body)
assert_kind_of Hash, xml['upload']
token = xml['upload']['token']
assert_not_nil token
attachment = Attachment.first(:order => 'id DESC')
assert_equal token, attachment.token
assert_nil attachment.container
assert_equal 2, attachment.author_id
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 File.exist?(attachment.diskfile)
assert_equal 'File content', File.read(attachment.diskfile)
end
end
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'))
assert_response 406
end
end
end
end