diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-02-23 10:01:16 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-02-23 10:01:16 +0000 |
commit | 77626ef6fbf2df028ccf01f6a72e459bfc70e2ab (patch) | |
tree | 226c3c315e1f3d3162dfac14535821156c703532 /test/integration/api_test/issues_test.rb | |
parent | d086683b17665719aa352074288b90ba954e6db0 (diff) | |
download | redmine-77626ef6fbf2df028ccf01f6a72e459bfc70e2ab.tar.gz redmine-77626ef6fbf2df028ccf01f6a72e459bfc70e2ab.zip |
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
Diffstat (limited to 'test/integration/api_test/issues_test.rb')
-rw-r--r-- | test/integration/api_test/issues_test.rb | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/integration/api_test/issues_test.rb b/test/integration/api_test/issues_test.rb index ae07deec5..2d9df063d 100644 --- a/test/integration/api_test/issues_test.rb +++ b/test/integration/api_test/issues_test.rb @@ -707,4 +707,72 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest assert_nil Issue.find_by_id(6) end end + + def test_create_issue_with_uploaded_file + set_tmp_attachments_directory + + # upload the file + assert_difference 'Attachment.count' do + post '/uploads.xml', 'test_create_with_upload', {'Content-Type' => 'application/octet-stream'}.merge(credentials('jsmith')) + assert_response :created + end + xml = Hash.from_xml(response.body) + token = xml['upload']['token'] + attachment = Attachment.first(:order => 'id DESC') + + # create the issue with the upload's token + assert_difference 'Issue.count' do + post '/issues.xml', + {:issue => {:project_id => 1, :subject => 'Uploaded file', :uploads => [{:token => token, :filename => 'test.txt', :content_type => 'text/plain'}]}}, + credentials('jsmith') + assert_response :created + end + issue = Issue.first(:order => 'id DESC') + assert_equal 1, issue.attachments.count + assert_equal attachment, issue.attachments.first + + attachment.reload + assert_equal 'test.txt', attachment.filename + assert_equal 'text/plain', attachment.content_type + assert_equal 'test_create_with_upload'.size, attachment.filesize + assert_equal 2, attachment.author_id + + # get the issue with its attachments + get "/issues/#{issue.id}.xml", :include => 'attachments' + assert_response :success + xml = Hash.from_xml(response.body) + attachments = xml['issue']['attachments'] + assert_kind_of Array, attachments + assert_equal 1, attachments.size + url = attachments.first['content_url'] + assert_not_nil url + + # download the attachment + get url + assert_response :success + end + + def test_update_issue_with_uploaded_file + set_tmp_attachments_directory + + # upload the file + assert_difference 'Attachment.count' do + post '/uploads.xml', 'test_upload_with_upload', {'Content-Type' => 'application/octet-stream'}.merge(credentials('jsmith')) + assert_response :created + end + xml = Hash.from_xml(response.body) + token = xml['upload']['token'] + attachment = Attachment.first(:order => 'id DESC') + + # update the issue with the upload's token + assert_difference 'Journal.count' do + put '/issues/1.xml', + {:issue => {:notes => 'Attachment added', :uploads => [{:token => token, :filename => 'test.txt', :content_type => 'text/plain'}]}}, + credentials('jsmith') + assert_response :ok + end + + issue = Issue.find(1) + assert_include attachment, issue.attachments + end end |