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