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.

group_test.rb 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 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 GroupTest < ActiveSupport::TestCase
  19. fixtures :projects, :trackers, :issue_statuses, :issues,
  20. :enumerations, :users, :issue_categories,
  21. :projects_trackers,
  22. :roles,
  23. :member_roles,
  24. :members,
  25. :enabled_modules,
  26. :workflows,
  27. :groups_users
  28. include Redmine::I18n
  29. def test_create
  30. g = Group.new(:lastname => 'New group')
  31. assert g.save
  32. end
  33. def test_blank_name_error_message
  34. set_language_if_valid 'en'
  35. g = Group.new
  36. assert !g.save
  37. assert_include "Name can't be blank", g.errors.full_messages
  38. end
  39. def test_blank_name_error_message_fr
  40. set_language_if_valid 'fr'
  41. str = "Nom doit \xc3\xaatre renseign\xc3\xa9(e)"
  42. str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
  43. g = Group.new
  44. assert !g.save
  45. assert_include str, g.errors.full_messages
  46. end
  47. def test_roles_given_to_new_user
  48. group = Group.find(11)
  49. user = User.find(9)
  50. project = Project.first
  51. Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
  52. group.users << user
  53. assert user.member_of?(project)
  54. end
  55. def test_roles_given_to_existing_user
  56. group = Group.find(11)
  57. user = User.find(9)
  58. project = Project.first
  59. group.users << user
  60. m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
  61. assert user.member_of?(project)
  62. end
  63. def test_roles_updated
  64. group = Group.find(11)
  65. user = User.find(9)
  66. project = Project.first
  67. group.users << user
  68. m = Member.create!(:principal => group, :project => project, :role_ids => [1])
  69. assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort
  70. m.role_ids = [1, 2]
  71. assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort
  72. m.role_ids = [2]
  73. assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort
  74. m.role_ids = [1]
  75. assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort
  76. end
  77. def test_roles_removed_when_removing_group_membership
  78. assert User.find(8).member_of?(Project.find(5))
  79. Member.find_by_project_id_and_user_id(5, 10).destroy
  80. assert !User.find(8).member_of?(Project.find(5))
  81. end
  82. def test_roles_removed_when_removing_user_from_group
  83. assert User.find(8).member_of?(Project.find(5))
  84. User.find(8).groups.clear
  85. assert !User.find(8).member_of?(Project.find(5))
  86. end
  87. def test_destroy_should_unassign_issues
  88. group = Group.first
  89. Issue.update_all(["assigned_to_id = ?", group.id], 'id = 1')
  90. assert group.destroy
  91. assert group.destroyed?
  92. assert_equal nil, Issue.find(1).assigned_to_id
  93. end
  94. end