Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

version_helper_test.rb 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- 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_relative '../test_helper'
  19. class VersionsHelperTest < Redmine::HelperTest
  20. include Rails.application.routes.url_helpers
  21. fixtures :projects, :versions, :enabled_modules,
  22. :users, :members, :roles, :member_roles,
  23. :trackers, :projects_trackers,
  24. :issue_statuses
  25. def test_version_filtered_issues_path_sharing_none
  26. version = Version.new(:name => 'test', :sharing => 'none')
  27. version.project = Project.find(5)
  28. assert_match '/projects/private-child/issues?', version_filtered_issues_path(version)
  29. end
  30. def test_version_filtered_issues_path_sharing_descendants
  31. version = Version.new(:name => 'test', :sharing => 'descendants')
  32. version.project = Project.find(5)
  33. assert_match '/projects/private-child/issues?', version_filtered_issues_path(version)
  34. end
  35. def test_version_filtered_issues_path_sharing_hierarchy
  36. version = Version.new(:name => 'test', :sharing => 'hierarchy')
  37. version.project = Project.find(5)
  38. assert_match '/projects/private-child/issues?', version_filtered_issues_path(version)
  39. end
  40. def test_version_filtered_issues_path_sharing_tree
  41. version = Version.new(:name => 'test', :sharing => 'tree')
  42. version.project = Project.find(5)
  43. assert_match '/projects/ecookbook/issues?', version_filtered_issues_path(version)
  44. end
  45. def test_version_filtered_issues_path_sharing_tree_without_permission_to_root_project
  46. EnabledModule.where("name = 'issue_tracking' AND project_id = 1").delete_all
  47. version = Version.new(:name => 'test', :sharing => 'tree')
  48. version.project = Project.find(5)
  49. assert_no_match '/projects/ecookbook/issues?', version_filtered_issues_path(version)
  50. assert_match '/issues?', version_filtered_issues_path(version)
  51. end
  52. def test_version_filtered_issues_path_sharing_system
  53. version = Version.new(:name => 'test', :sharing => 'system')
  54. version.project = Project.find(5)
  55. assert_match /^\/issues\?/, version_filtered_issues_path(version)
  56. end
  57. def test_link_to_new_issue_should_return_link_to_add_issue
  58. version = Version.find(3)
  59. project = Project.find(1)
  60. User.current = User.find(1)
  61. # href should contain the following params:
  62. # fixed_version_id=3
  63. # tracker_id=1
  64. assert_select_in(
  65. link_to_new_issue(version, project),
  66. '[href=?]',
  67. '/projects/ecookbook/issues/new?back_url=' \
  68. '%2Fversions%2F3&issue%5Bfixed_version_id%5D=3&issue%5Btracker_id%5D=1',
  69. :text => 'New issue'
  70. )
  71. end
  72. def test_link_to_new_issue_should_return_nil_if_version_status_is_not_open
  73. # locked version
  74. version = Version.find(2)
  75. project = Project.find(1)
  76. User.current = User.find(1)
  77. assert_nil link_to_new_issue(version, project)
  78. end
  79. def test_link_to_new_issue_should_return_nil_if_user_does_not_have_permission_to_add_issue
  80. Role.find(1).remove_permission! :add_issues
  81. version = Version.find(3)
  82. project = Project.find(1)
  83. User.current = User.find(2)
  84. assert_nil link_to_new_issue(version, project)
  85. end
  86. def test_link_to_new_issue_should_return_nil_if_no_tracker_is_available_for_project
  87. trackers = Tracker::CORE_FIELDS - %w(fixed_version_id)
  88. # disable fixed_version_id field for all trackers
  89. Tracker.all.each do |tracker|
  90. tracker.core_fields = trackers
  91. tracker.save!
  92. end
  93. version = Version.find(3)
  94. project = Project.find(1)
  95. User.current = User.find(2)
  96. assert_nil link_to_new_issue(version, project)
  97. end
  98. def test_link_to_new_issue_should_take_into_account_user_permissions_on_fixed_version_id_field
  99. WorkflowPermission.delete_all
  100. WorkflowPermission.create!(:role_id => 1, :tracker_id => 1,
  101. :old_status_id => 1,
  102. :field_name => 'fixed_version_id',
  103. :rule => 'readonly')
  104. version = Version.find(3)
  105. project = Project.find(1)
  106. User.current = User.find(2)
  107. # href should contain param tracker_id=2 because for tracker_id 1,
  108. # user has only readonly permissions on fixed_version_id
  109. assert_select_in(
  110. link_to_new_issue(version, project),
  111. '[href=?]',
  112. '/projects/ecookbook/issues/new?back_url=' \
  113. '%2Fversions%2F3&issue%5Bfixed_version_id%5D=3&issue%5Btracker_id%5D=2'
  114. )
  115. end
  116. end