##// END OF EJS Templates
Include value and label of possible values in custom fields API (#22745)....
Jean-Philippe Lang -
r15019:60bb7565dd84
parent child
Show More
@@ -1,43 +1,44
1 1 api.array :custom_fields do
2 2 @custom_fields.each do |field|
3 3 api.custom_field do
4 4 api.id field.id
5 5 api.name field.name
6 6 api.customized_type field.class.customized_class.name.underscore if field.class.customized_class
7 7 api.field_format field.field_format
8 8 api.regexp field.regexp
9 9 api.min_length field.min_length
10 10 api.max_length field.max_length
11 11 api.is_required field.is_required?
12 12 api.is_filter field.is_filter?
13 13 api.searchable field.searchable
14 14 api.multiple field.multiple?
15 15 api.default_value field.default_value
16 16 api.visible field.visible?
17 17
18 18 values = field.possible_values_options
19 19 if values.present?
20 20 api.array :possible_values do
21 21 values.each do |label, value|
22 22 api.possible_value do
23 23 api.value value || label
24 api.label label
24 25 end
25 26 end
26 27 end
27 28 end
28 29
29 30 if field.is_a?(IssueCustomField)
30 31 api.array :trackers do
31 32 field.trackers.each do |tracker|
32 33 api.tracker :id => tracker.id, :name => tracker.name
33 34 end
34 35 end
35 36 api.array :roles do
36 37 field.roles.each do |role|
37 38 api.role :id => role.id, :name => role.name
38 39 end
39 40 end
40 41 end
41 42 end
42 43 end
43 44 end
@@ -1,41 +1,56
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2016 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../../test_helper', __FILE__)
19 19
20 20 class Redmine::ApiTest::CustomFieldsTest < Redmine::ApiTest::Base
21 21 fixtures :users, :custom_fields
22 22
23 23 test "GET /custom_fields.xml should return custom fields" do
24 24 get '/custom_fields.xml', {}, credentials('admin')
25 25 assert_response :success
26 26 assert_equal 'application/xml', response.content_type
27 27
28 28 assert_select 'custom_fields' do
29 29 assert_select 'custom_field' do
30 30 assert_select 'name', :text => 'Database'
31 31 assert_select 'id', :text => '2'
32 32 assert_select 'customized_type', :text => 'issue'
33 33 assert_select 'possible_values[type=array]' do
34 34 assert_select 'possible_value>value', :text => 'PostgreSQL'
35 assert_select 'possible_value>label', :text => 'PostgreSQL'
35 36 end
36 37 assert_select 'trackers[type=array]'
37 38 assert_select 'roles[type=array]'
38 39 end
39 40 end
40 41 end
42
43 test "GET /custom_fields.xml should include value and label for enumeration custom fields" do
44 field = IssueCustomField.generate!(:field_format => 'enumeration')
45 foo = field.enumerations.create!(:name => 'Foo')
46 bar = field.enumerations.create!(:name => 'Bar')
47
48 get '/custom_fields.xml', {}, credentials('admin')
49 assert_response :success
50
51 assert_select 'possible_value' do
52 assert_select "value:contains(?) + label:contains(?)", foo.id.to_s, 'Foo'
53 assert_select "value:contains(?) + label:contains(?)", bar.id.to_s, 'Bar'
54 end
55 end
41 56 end
General Comments 0
You need to be logged in to leave comments. Login now