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_field_user_format_test.rb 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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 CustomFieldUserFormatTest < ActiveSupport::TestCase
  19. fixtures :custom_fields, :projects, :members, :users, :member_roles, :trackers, :issues
  20. def setup
  21. User.current = nil
  22. @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user')
  23. end
  24. def test_possible_values_options_with_no_arguments
  25. assert_equal [], @field.possible_values_options
  26. assert_equal [], @field.possible_values_options(nil)
  27. end
  28. def test_possible_values_options_with_project_resource
  29. project = Project.find(1)
  30. possible_values_options = @field.possible_values_options(project.issues.first)
  31. assert possible_values_options.any?
  32. assert_equal project.users.sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
  33. end
  34. def test_possible_values_options_with_array
  35. projects = Project.find([1, 2])
  36. possible_values_options = @field.possible_values_options(projects)
  37. assert possible_values_options.any?
  38. assert_equal (projects.first.users & projects.last.users).sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
  39. end
  40. def test_possible_custom_value_options_should_not_include_locked_users
  41. custom_value = CustomValue.new(:customized => Issue.find(1), :custom_field => @field)
  42. assert_include '2', @field.possible_custom_value_options(custom_value).map(&:last)
  43. assert User.find(2).lock!
  44. assert_not_include '2', @field.possible_custom_value_options(custom_value).map(&:last)
  45. end
  46. def test_possible_custom_value_options_should_include_user_that_was_assigned_to_the_custom_value
  47. user = User.generate!
  48. custom_value = CustomValue.new(:customized => Issue.find(1), :custom_field => @field)
  49. assert_not_include user.id.to_s, @field.possible_custom_value_options(custom_value).map(&:last)
  50. custom_value.value = user.id
  51. custom_value.save!
  52. assert_include user.id.to_s, @field.possible_custom_value_options(custom_value).map(&:last)
  53. end
  54. def test_cast_blank_value
  55. assert_nil @field.cast_value(nil)
  56. assert_nil @field.cast_value("")
  57. end
  58. def test_cast_valid_value
  59. user = @field.cast_value("2")
  60. assert_kind_of User, user
  61. assert_equal User.find(2), user
  62. end
  63. def test_cast_invalid_value
  64. assert_nil @field.cast_value("187")
  65. end
  66. end