From 5a3b9037333e4ff6f3727b0fb058b560be38240a Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 1 May 2013 15:57:31 +0000 Subject: [PATCH] Fixed: Unable to set custom fields for versions using the REST API (#13850). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11760 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/version.rb | 3 ++- test/integration/api_test/versions_test.rb | 23 ++++++++++++++++++++++ test/object_helpers.rb | 11 +++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/models/version.rb b/app/models/version.rb index 0c081baa6..e386af53d 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -47,7 +47,8 @@ class Version < ActiveRecord::Base 'wiki_page_title', 'status', 'sharing', - 'custom_field_values' + 'custom_field_values', + 'custom_fields' # Returns true if +user+ or current user is allowed to view the version def visible?(user=User.current) diff --git a/test/integration/api_test/versions_test.rb b/test/integration/api_test/versions_test.rb index 8be37534a..51f8e2b33 100644 --- a/test/integration/api_test/versions_test.rb +++ b/test/integration/api_test/versions_test.rb @@ -82,6 +82,29 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s} end + should "create the version with custom fields" do + field = VersionCustomField.generate! + + assert_difference 'Version.count' do + post '/projects/1/versions.xml', { + :version => { + :name => 'API test', + :custom_fields => [ + {'id' => field.id.to_s, 'value' => 'Some value'} + ] + } + }, credentials('jsmith') + end + + version = Version.first(:order => 'id DESC') + assert_equal 'API test', version.name + assert_equal 'Some value', version.custom_field_value(field) + + assert_response :created + assert_equal 'application/xml', @response.content_type + assert_select 'version>custom_fields>custom_field[id=?]>value', field.id.to_s, 'Some value' + end + context "with failure" do should "return the errors" do assert_no_difference('Version.count') do diff --git a/test/object_helpers.rb b/test/object_helpers.rb index 0b6ec01d8..8c82a328b 100644 --- a/test/object_helpers.rb +++ b/test/object_helpers.rb @@ -147,4 +147,15 @@ module ObjectHelpers attachment.save! attachment end + + def CustomField.generate!(attributes={}) + @generated_custom_field_name ||= 'Custom field 0' + @generated_custom_field_name.succ! + field = new(attributes) + field.name = @generated_custom_field_name.dup if field.name.blank? + field.field_format = 'string' if field.field_format.blank? + yield field if block_given? + field.save! + field + end end -- 2.39.5