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.

versions_custom_fields_visibility_test.rb 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 VersionsCustomFieldsVisibilityTest < Redmine::ControllerTest
  20. tests VersionsController
  21. fixtures :projects,
  22. :users, :email_addresses,
  23. :roles,
  24. :members,
  25. :member_roles,
  26. :issue_statuses,
  27. :trackers,
  28. :projects_trackers,
  29. :enabled_modules,
  30. :versions,
  31. :custom_fields, :custom_values, :custom_fields_trackers
  32. def test_show_should_display_only_custom_fields_visible_to_user
  33. cf1 = VersionCustomField.create!(:name => 'cf1', :field_format => 'string')
  34. cf2 = VersionCustomField.create!(:name => 'cf2', :field_format => 'string', :visible => false, :role_ids => [1])
  35. cf3 = VersionCustomField.create!(:name => 'cf3', :field_format => 'string', :visible => false, :role_ids => [3])
  36. version = Version.find(2)
  37. version.custom_field_values = {cf1.id => 'Value1', cf2.id => 'Value2', cf3.id => 'Value3'}
  38. version.save!
  39. @request.session[:user_id] = 2
  40. get(:show, :params => {:id => 2})
  41. assert_response :success
  42. assert_select '#roadmap' do
  43. assert_select 'span.label', :text => 'cf1:'
  44. assert_select 'span.label', :text => 'cf2:'
  45. assert_select 'span.label', {count: 0, text: 'cf3:'}
  46. end
  47. end
  48. def test_edit_should_display_only_custom_fields_visible_to_user
  49. cf1 = VersionCustomField.create!(:name => 'cf1', :field_format => 'string')
  50. cf2 = VersionCustomField.create!(:name => 'cf2', :field_format => 'string', :visible => false, :role_ids => [1])
  51. cf3 = VersionCustomField.create!(:name => 'cf3', :field_format => 'string', :visible => false, :role_ids => [3])
  52. version = Version.find(2)
  53. version.custom_field_values = {cf1.id => 'Value1', cf2.id => 'Value2', cf3.id => 'Value3'}
  54. version.save!
  55. @request.session[:user_id] = 2
  56. get(:edit, :params => {:id => 2})
  57. assert_response :success
  58. assert_select 'form.edit_version' do
  59. assert_select 'input[id=?]', "version_custom_field_values_#{cf1.id}"
  60. assert_select 'input[id=?]', "version_custom_field_values_#{cf2.id}"
  61. assert_select 'input[id=?]', "version_custom_field_values_#{cf3.id}", 0
  62. end
  63. end
  64. end