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 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2014 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. @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user')
  22. end
  23. def test_possible_values_with_no_arguments
  24. assert_equal [], @field.possible_values
  25. assert_equal [], @field.possible_values(nil)
  26. end
  27. def test_possible_values_with_project_resource
  28. project = Project.find(1)
  29. possible_values = @field.possible_values(project.issues.first)
  30. assert possible_values.any?
  31. assert_equal project.users.sort.collect(&:id).map(&:to_s), possible_values
  32. end
  33. def test_possible_values_with_nil_project_resource
  34. project = Project.find(1)
  35. assert_equal [], @field.possible_values(Issue.new)
  36. end
  37. def test_possible_values_options_with_no_arguments
  38. assert_equal [], @field.possible_values_options
  39. assert_equal [], @field.possible_values_options(nil)
  40. end
  41. def test_possible_values_options_with_project_resource
  42. project = Project.find(1)
  43. possible_values_options = @field.possible_values_options(project.issues.first)
  44. assert possible_values_options.any?
  45. assert_equal project.users.sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
  46. end
  47. def test_possible_values_options_with_array
  48. projects = Project.find([1, 2])
  49. possible_values_options = @field.possible_values_options(projects)
  50. assert possible_values_options.any?
  51. assert_equal (projects.first.users & projects.last.users).sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
  52. end
  53. def test_cast_blank_value
  54. assert_equal nil, @field.cast_value(nil)
  55. assert_equal nil, @field.cast_value("")
  56. end
  57. def test_cast_valid_value
  58. user = @field.cast_value("2")
  59. assert_kind_of User, user
  60. assert_equal User.find(2), user
  61. end
  62. def test_cast_invalid_value
  63. assert_equal nil, @field.cast_value("187")
  64. end
  65. end