@@ -1,63 +1,63 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 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::CustomFieldsAttributeTest < Redmine::ApiTest::Base |
|
20 | class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base | |
21 | fixtures :users |
|
21 | fixtures :users | |
22 |
|
22 | |||
23 | def test_integer_custom_fields_should_accept_strings |
|
23 | def test_integer_custom_fields_should_accept_strings | |
24 | field = GroupCustomField.generate!(:field_format => 'int') |
|
24 | field = GroupCustomField.generate!(:field_format => 'int') | |
25 |
|
25 | |||
26 | post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":"52"}}}), |
|
26 | post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":"52"}}}), | |
27 | {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin')) |
|
27 | {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin')) | |
28 | assert_response :created |
|
28 | assert_response :created | |
29 | group = Group.order('id DESC').first |
|
29 | group = Group.order('id DESC').first | |
30 | assert_equal "52", group.custom_field_value(field) |
|
30 | assert_equal "52", group.custom_field_value(field) | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def test_integer_custom_fields_should_accept_integers |
|
33 | def test_integer_custom_fields_should_accept_integers | |
34 | field = GroupCustomField.generate!(:field_format => 'int') |
|
34 | field = GroupCustomField.generate!(:field_format => 'int') | |
35 |
|
35 | |||
36 | post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":52}}}), |
|
36 | post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":52}}}), | |
37 | {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin')) |
|
37 | {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin')) | |
38 | assert_response :created |
|
38 | assert_response :created | |
39 | group = Group.order('id DESC').first |
|
39 | group = Group.order('id DESC').first | |
40 | assert_equal "52", group.custom_field_value(field) |
|
40 | assert_equal "52", group.custom_field_value(field) | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | def test_multivalued_custom_fields_should_accept_an_array |
|
43 | def test_multivalued_custom_fields_should_accept_an_array | |
44 | field = GroupCustomField.generate!( |
|
44 | field = GroupCustomField.generate!( | |
45 | :field_format => 'list', |
|
45 | :field_format => 'list', | |
46 | :multiple => true, |
|
46 | :multiple => true, | |
47 | :possible_values => ["V1", "V2", "V3"], |
|
47 | :possible_values => ["V1", "V2", "V3"], | |
48 | :default_value => "V2" |
|
48 | :default_value => "V2" | |
49 | ) |
|
49 | ) | |
50 |
|
50 | |||
51 | payload = <<-JSON |
|
51 | payload = <<-JSON | |
52 | {"group": {"name":"Foooo", |
|
52 | {"group": {"name":"Foooo", | |
53 | "custom_field_values":{"#{field.id}":["V1","V3"]} |
|
53 | "custom_field_values":{"#{field.id}":["V1","V3"]} | |
54 | } |
|
54 | } | |
55 | } |
|
55 | } | |
56 | JSON |
|
56 | JSON | |
57 |
|
57 | |||
58 | post '/groups.json', payload, {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin')) |
|
58 | post '/groups.json', payload, {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin')) | |
59 | assert_response :created |
|
59 | assert_response :created | |
60 | group = Group.order('id DESC').first |
|
60 | group = Group.order('id DESC').first | |
61 | assert_equal ["V1", "V3"], group.custom_field_value(field) |
|
61 | assert_equal ["V1", "V3"], group.custom_field_value(field).sort | |
62 | end |
|
62 | end | |
63 | end |
|
63 | end |
General Comments 0
You need to be logged in to leave comments.
Login now