summaryrefslogtreecommitdiffstats
path: root/test/integration/api_test
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-01-29 20:51:48 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-01-29 20:51:48 +0000
commitcd6db6a3cbe43880eca4eec8c967fb78d95a2926 (patch)
tree42219d3f9b276f197f5045cec25639bb4e2be5fd /test/integration/api_test
parent0c5af16e14570a384e154430cd1e9fa123cdf579 (diff)
downloadredmine-cd6db6a3cbe43880eca4eec8c967fb78d95a2926.tar.gz
redmine-cd6db6a3cbe43880eca4eec8c967fb78d95a2926.zip
Adds support for multiselect custom fields (#1189).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8721 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/integration/api_test')
-rw-r--r--test/integration/api_test/issues_test.rb120
1 files changed, 120 insertions, 0 deletions
diff --git a/test/integration/api_test/issues_test.rb b/test/integration/api_test/issues_test.rb
index 0b7593e3f..5d40b3c85 100644
--- a/test/integration/api_test/issues_test.rb
+++ b/test/integration/api_test/issues_test.rb
@@ -258,6 +258,108 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
end
end
+ context "with multi custom fields" do
+ setup do
+ field = CustomField.find(1)
+ field.update_attribute :multiple, true
+ issue = Issue.find(3)
+ issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
+ issue.save!
+ end
+
+ context ".xml" do
+ should "display custom fields" do
+ get '/issues/3.xml'
+ assert_response :success
+ assert_tag :tag => 'issue',
+ :child => {
+ :tag => 'custom_fields',
+ :attributes => { :type => 'array' },
+ :child => {
+ :tag => 'custom_field',
+ :attributes => { :id => '1'},
+ :child => {
+ :tag => 'value',
+ :attributes => { :type => 'array' },
+ :children => { :count => 2 }
+ }
+ }
+ }
+
+ xml = Hash.from_xml(response.body)
+ custom_fields = xml['issue']['custom_fields']
+ assert_kind_of Array, custom_fields
+ field = custom_fields.detect {|f| f['id'] == '1'}
+ assert_kind_of Hash, field
+ assert_equal ['MySQL', 'Oracle'], field['value'].sort
+ end
+ end
+
+ context ".json" do
+ should "display custom fields" do
+ get '/issues/3.json'
+ assert_response :success
+ json = ActiveSupport::JSON.decode(response.body)
+ custom_fields = json['issue']['custom_fields']
+ assert_kind_of Array, custom_fields
+ field = custom_fields.detect {|f| f['id'] == 1}
+ assert_kind_of Hash, field
+ assert_equal ['MySQL', 'Oracle'], field['value'].sort
+ end
+ end
+ end
+
+ context "with empty value for multi custom field" do
+ setup do
+ field = CustomField.find(1)
+ field.update_attribute :multiple, true
+ issue = Issue.find(3)
+ issue.custom_field_values = {1 => ['']}
+ issue.save!
+ end
+
+ context ".xml" do
+ should "display custom fields" do
+ get '/issues/3.xml'
+ assert_response :success
+ assert_tag :tag => 'issue',
+ :child => {
+ :tag => 'custom_fields',
+ :attributes => { :type => 'array' },
+ :child => {
+ :tag => 'custom_field',
+ :attributes => { :id => '1'},
+ :child => {
+ :tag => 'value',
+ :attributes => { :type => 'array' },
+ :children => { :count => 0 }
+ }
+ }
+ }
+
+ xml = Hash.from_xml(response.body)
+ custom_fields = xml['issue']['custom_fields']
+ assert_kind_of Array, custom_fields
+ field = custom_fields.detect {|f| f['id'] == '1'}
+ assert_kind_of Hash, field
+ assert_equal [], field['value']
+ end
+ end
+
+ context ".json" do
+ should "display custom fields" do
+ get '/issues/3.json'
+ assert_response :success
+ json = ActiveSupport::JSON.decode(response.body)
+ custom_fields = json['issue']['custom_fields']
+ assert_kind_of Array, custom_fields
+ field = custom_fields.detect {|f| f['id'] == 1}
+ assert_kind_of Hash, field
+ assert_equal [], field['value'].sort
+ end
+ end
+ end
+
context "with attachments" do
context ".xml" do
should "display attachments" do
@@ -455,6 +557,24 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
end
end
+ context "PUT /issues/3.xml with multi custom fields" do
+ setup do
+ field = CustomField.find(1)
+ field.update_attribute :multiple, true
+ @parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => ['MySQL', 'PostgreSQL'] }, {'id' => '2', 'value' => '150'}]}}
+ end
+
+ should "update custom fields" do
+ assert_no_difference('Issue.count') do
+ put '/issues/3.xml', @parameters, credentials('jsmith')
+ end
+
+ issue = Issue.find(3)
+ assert_equal '150', issue.custom_value_for(2).value
+ assert_equal ['MySQL', 'PostgreSQL'], issue.custom_field_value(1)
+ end
+ end
+
context "PUT /issues/3.xml with project change" do
setup do
@parameters = {:issue => {:project_id => 2, :subject => 'Project changed'}}