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.

access_control_test.rb 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 Redmine::AccessControlTest < ActiveSupport::TestCase
  19. def setup
  20. @access_module = Redmine::AccessControl
  21. end
  22. def test_permissions
  23. perms = @access_module.permissions
  24. assert perms.is_a?(Array)
  25. assert perms.first.is_a?(Redmine::AccessControl::Permission)
  26. end
  27. def test_module_permission
  28. perm = @access_module.permission(:view_issues)
  29. assert perm.is_a?(Redmine::AccessControl::Permission)
  30. assert_equal :view_issues, perm.name
  31. assert_equal :issue_tracking, perm.project_module
  32. assert perm.actions.is_a?(Array)
  33. assert perm.actions.include?('issues/index')
  34. end
  35. def test_no_module_permission
  36. perm = @access_module.permission(:edit_project)
  37. assert perm.is_a?(Redmine::AccessControl::Permission)
  38. assert_equal :edit_project, perm.name
  39. assert_nil perm.project_module
  40. assert perm.actions.is_a?(Array)
  41. assert perm.actions.include?('projects/settings')
  42. end
  43. def test_read_action_should_return_true_for_read_actions
  44. assert_equal true, @access_module.read_action?(:view_project)
  45. assert_equal true, @access_module.read_action?(:controller => 'projects', :action => 'show')
  46. end
  47. def test_read_action_should_return_false_for_update_actions
  48. assert_equal false, @access_module.read_action?(:edit_project)
  49. assert_equal false, @access_module.read_action?(:controller => 'projects', :action => 'edit')
  50. end
  51. end