From 9b082712a09146b4237cf3427dce6293ba748643 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 22 Dec 2014 13:41:51 +0000 Subject: Adds tests for creating an issue with multiple uploads. git-svn-id: http://svn.redmine.org/redmine/trunk@13791 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/test_helper.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'test/test_helper.rb') diff --git a/test/test_helper.rb b/test/test_helper.rb index 44ea86f5b..22b96a809 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -271,6 +271,45 @@ module Redmine def teardown Setting.rest_api_enabled = '0' end + + # Uploads content using the XML API and returns the attachment token + def xml_upload(content, credentials) + upload('xml', content, credentials) + end + + # Uploads content using the JSON API and returns the attachment token + def json_upload(content, credentials) + upload('json', content, credentials) + end + + def upload(format, content, credentials) + set_tmp_attachments_directory + assert_difference 'Attachment.count' do + post "/uploads.#{format}", content, {"CONTENT_TYPE" => 'application/octet-stream'}.merge(credentials) + assert_response :created + end + data = response_data + assert_kind_of Hash, data['upload'] + token = data['upload']['token'] + assert_not_nil token + token + end + + # Parses the response body based on its content type + def response_data + unless response.content_type.to_s =~ /^application\/(.+)/ + raise "Unexpected response type: #{response.content_type}" + end + format = $1 + case format + when 'xml' + Hash.from_xml(response.body) + when 'json' + ActiveSupport::JSON.decode(response.body) + else + raise "Unknown response format: #{format}" + end + end end class Routing < Redmine::RoutingTest -- cgit v1.2.3