Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

custom_field_version_format_test.rb 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../test_helper', __FILE__)
  19. class CustomFieldVersionFormatTest < ActiveSupport::TestCase
  20. fixtures :custom_fields, :projects, :members, :users, :member_roles, :trackers, :issues, :versions
  21. def setup
  22. User.current = nil
  23. @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'version')
  24. end
  25. def test_possible_values_options_with_no_arguments
  26. Version.delete_all
  27. assert_equal [], @field.possible_values_options
  28. assert_equal [], @field.possible_values_options(nil)
  29. end
  30. def test_possible_values_options_with_project_resource
  31. project = Project.find(1)
  32. possible_values_options = @field.possible_values_options(project.issues.first)
  33. assert possible_values_options.any?
  34. assert_equal project.shared_versions.sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
  35. end
  36. def test_possible_values_options_with_array
  37. projects = Project.find([1, 2])
  38. possible_values_options = @field.possible_values_options(projects)
  39. assert possible_values_options.any?
  40. assert_equal (projects.first.shared_versions & projects.last.shared_versions).sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
  41. end
  42. def test_cast_blank_value
  43. assert_nil @field.cast_value(nil)
  44. assert_nil @field.cast_value("")
  45. end
  46. def test_cast_valid_value
  47. version = @field.cast_value("2")
  48. assert_kind_of Version, version
  49. assert_equal Version.find(2), version
  50. end
  51. def test_cast_invalid_value
  52. assert_nil @field.cast_value("187")
  53. end
  54. end