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.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 CustomFieldVersionFormatTest < ActiveSupport::TestCase
  19. fixtures :custom_fields, :projects, :members, :users, :member_roles, :trackers, :issues, :versions
  20. def setup
  21. User.current = nil
  22. @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'version')
  23. end
  24. def test_possible_values_options_with_no_arguments
  25. Version.delete_all
  26. assert_equal [], @field.possible_values_options
  27. assert_equal [], @field.possible_values_options(nil)
  28. end
  29. def test_possible_values_options_with_project_resource
  30. project = Project.find(1)
  31. possible_values_options = @field.possible_values_options(project.issues.first)
  32. assert possible_values_options.any?
  33. assert_equal project.shared_versions.sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
  34. end
  35. def test_possible_values_options_with_array
  36. projects = Project.find([1, 2])
  37. possible_values_options = @field.possible_values_options(projects)
  38. assert possible_values_options.any?
  39. assert_equal (projects.first.shared_versions & projects.last.shared_versions).sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
  40. end
  41. def test_cast_blank_value
  42. assert_nil @field.cast_value(nil)
  43. assert_nil @field.cast_value("")
  44. end
  45. def test_cast_valid_value
  46. version = @field.cast_value("2")
  47. assert_kind_of Version, version
  48. assert_equal Version.find(2), version
  49. end
  50. def test_cast_invalid_value
  51. assert_nil @field.cast_value("187")
  52. end
  53. end