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_version_format_test.rb 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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 CustomFieldVersionFormatTest < ActiveSupport::TestCase
  19. fixtures :custom_fields, :projects, :members, :users, :member_roles, :trackers, :issues, :versions
  20. def setup
  21. @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'version')
  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.shared_versions.sort.collect(&:id).map(&:to_s), possible_values
  32. end
  33. def test_possible_values_with_nil_project_resource
  34. assert_equal [], @field.possible_values(Issue.new)
  35. end
  36. def test_possible_values_options_with_no_arguments
  37. assert_equal [], @field.possible_values_options
  38. assert_equal [], @field.possible_values_options(nil)
  39. end
  40. def test_possible_values_options_with_project_resource
  41. project = Project.find(1)
  42. possible_values_options = @field.possible_values_options(project.issues.first)
  43. assert possible_values_options.any?
  44. assert_equal project.shared_versions.sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
  45. end
  46. def test_possible_values_options_with_array
  47. projects = Project.find([1, 2])
  48. possible_values_options = @field.possible_values_options(projects)
  49. assert possible_values_options.any?
  50. assert_equal (projects.first.shared_versions & projects.last.shared_versions).sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
  51. end
  52. def test_cast_blank_value
  53. assert_equal nil, @field.cast_value(nil)
  54. assert_equal nil, @field.cast_value("")
  55. end
  56. def test_cast_valid_value
  57. version = @field.cast_value("2")
  58. assert_kind_of Version, version
  59. assert_equal Version.find(2), version
  60. end
  61. def test_cast_invalid_value
  62. assert_equal nil, @field.cast_value("187")
  63. end
  64. end