You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

custom_fields_attribute_test.rb 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2016 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  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
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../../test_helper', __FILE__)
  18. class Redmine::ApiTest::CustomFieldsAttributeTest < Redmine::ApiTest::Base
  19. fixtures :users
  20. def test_integer_custom_fields_should_accept_strings
  21. field = GroupCustomField.generate!(:field_format => 'int')
  22. post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":"52"}}}),
  23. {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin'))
  24. assert_response :created
  25. group = Group.order('id DESC').first
  26. assert_equal "52", group.custom_field_value(field)
  27. end
  28. def test_integer_custom_fields_should_accept_integers
  29. field = GroupCustomField.generate!(:field_format => 'int')
  30. post '/groups.json', %({"group":{"name":"Foo","custom_field_values":{"#{field.id}":52}}}),
  31. {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin'))
  32. assert_response :created
  33. group = Group.order('id DESC').first
  34. assert_equal "52", group.custom_field_value(field)
  35. end
  36. def test_multivalued_custom_fields_should_accept_an_array
  37. field = GroupCustomField.generate!(
  38. :field_format => 'list',
  39. :multiple => true,
  40. :possible_values => ["V1", "V2", "V3"],
  41. :default_value => "V2"
  42. )
  43. payload = <<-JSON
  44. {"group": {"name":"Foooo",
  45. "custom_field_values":{"#{field.id}":["V1","V3"]}
  46. }
  47. }
  48. JSON
  49. post '/groups.json', payload, {'CONTENT_TYPE' => 'application/json'}.merge(credentials('admin'))
  50. assert_response :created
  51. group = Group.order('id DESC').first
  52. assert_equal ["V1", "V3"], group.custom_field_value(field).sort
  53. end
  54. end