Chris@0
|
1 # Redmine - project management software
|
Chris@1494
|
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@909
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@909
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@119
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19
|
Chris@0
|
20 class GroupTest < ActiveSupport::TestCase
|
Chris@909
|
21 fixtures :projects, :trackers, :issue_statuses, :issues,
|
Chris@1464
|
22 :enumerations, :users,
|
Chris@909
|
23 :projects_trackers,
|
Chris@909
|
24 :roles,
|
Chris@909
|
25 :member_roles,
|
Chris@909
|
26 :members,
|
Chris@909
|
27 :groups_users
|
Chris@909
|
28
|
Chris@909
|
29 include Redmine::I18n
|
Chris@0
|
30
|
Chris@0
|
31 def test_create
|
Chris@1115
|
32 g = Group.new(:name => 'New group')
|
Chris@0
|
33 assert g.save
|
Chris@1115
|
34 g.reload
|
Chris@1115
|
35 assert_equal 'New group', g.name
|
Chris@0
|
36 end
|
Chris@909
|
37
|
Chris@1464
|
38 def test_name_should_accept_255_characters
|
Chris@1464
|
39 name = 'a' * 255
|
Chris@1464
|
40 g = Group.new(:name => name)
|
Chris@1464
|
41 assert g.save
|
Chris@1464
|
42 g.reload
|
Chris@1464
|
43 assert_equal name, g.name
|
Chris@1464
|
44 end
|
Chris@1464
|
45
|
Chris@909
|
46 def test_blank_name_error_message
|
Chris@909
|
47 set_language_if_valid 'en'
|
Chris@909
|
48 g = Group.new
|
Chris@909
|
49 assert !g.save
|
Chris@909
|
50 assert_include "Name can't be blank", g.errors.full_messages
|
Chris@909
|
51 end
|
Chris@909
|
52
|
Chris@909
|
53 def test_blank_name_error_message_fr
|
Chris@909
|
54 set_language_if_valid 'fr'
|
Chris@909
|
55 str = "Nom doit \xc3\xaatre renseign\xc3\xa9(e)"
|
Chris@909
|
56 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
|
Chris@909
|
57 g = Group.new
|
Chris@909
|
58 assert !g.save
|
Chris@909
|
59 assert_include str, g.errors.full_messages
|
Chris@909
|
60 end
|
Chris@909
|
61
|
Chris@1115
|
62 def test_group_roles_should_be_given_to_added_user
|
Chris@0
|
63 group = Group.find(11)
|
Chris@0
|
64 user = User.find(9)
|
Chris@0
|
65 project = Project.first
|
Chris@909
|
66
|
Chris@0
|
67 Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
|
Chris@0
|
68 group.users << user
|
Chris@0
|
69 assert user.member_of?(project)
|
Chris@0
|
70 end
|
Chris@909
|
71
|
Chris@1115
|
72 def test_new_roles_should_be_given_to_existing_user
|
Chris@0
|
73 group = Group.find(11)
|
Chris@0
|
74 user = User.find(9)
|
Chris@0
|
75 project = Project.first
|
Chris@909
|
76
|
Chris@0
|
77 group.users << user
|
Chris@0
|
78 m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
|
Chris@0
|
79 assert user.member_of?(project)
|
Chris@0
|
80 end
|
Chris@909
|
81
|
Chris@1115
|
82 def test_user_roles_should_updated_when_updating_user_ids
|
Chris@1115
|
83 group = Group.find(11)
|
Chris@1115
|
84 user = User.find(9)
|
Chris@1115
|
85 project = Project.first
|
Chris@1115
|
86
|
Chris@1115
|
87 Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
|
Chris@1115
|
88 group.user_ids = [user.id]
|
Chris@1115
|
89 group.save!
|
Chris@1115
|
90 assert User.find(9).member_of?(project)
|
Chris@1115
|
91
|
Chris@1115
|
92 group.user_ids = [1]
|
Chris@1115
|
93 group.save!
|
Chris@1115
|
94 assert !User.find(9).member_of?(project)
|
Chris@1115
|
95 end
|
Chris@1115
|
96
|
Chris@1115
|
97 def test_user_roles_should_updated_when_updating_group_roles
|
Chris@0
|
98 group = Group.find(11)
|
Chris@0
|
99 user = User.find(9)
|
Chris@0
|
100 project = Project.first
|
Chris@0
|
101 group.users << user
|
Chris@0
|
102 m = Member.create!(:principal => group, :project => project, :role_ids => [1])
|
Chris@0
|
103 assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort
|
Chris@909
|
104
|
Chris@0
|
105 m.role_ids = [1, 2]
|
Chris@0
|
106 assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort
|
Chris@909
|
107
|
Chris@0
|
108 m.role_ids = [2]
|
Chris@0
|
109 assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort
|
Chris@909
|
110
|
Chris@0
|
111 m.role_ids = [1]
|
Chris@0
|
112 assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort
|
Chris@0
|
113 end
|
Chris@0
|
114
|
Chris@1115
|
115 def test_user_memberships_should_be_removed_when_removing_group_membership
|
Chris@0
|
116 assert User.find(8).member_of?(Project.find(5))
|
Chris@0
|
117 Member.find_by_project_id_and_user_id(5, 10).destroy
|
Chris@0
|
118 assert !User.find(8).member_of?(Project.find(5))
|
Chris@0
|
119 end
|
Chris@0
|
120
|
Chris@1115
|
121 def test_user_roles_should_be_removed_when_removing_user_from_group
|
Chris@0
|
122 assert User.find(8).member_of?(Project.find(5))
|
Chris@1115
|
123 User.find(8).groups = []
|
Chris@0
|
124 assert !User.find(8).member_of?(Project.find(5))
|
Chris@0
|
125 end
|
Chris@909
|
126
|
Chris@909
|
127 def test_destroy_should_unassign_issues
|
Chris@909
|
128 group = Group.first
|
Chris@1517
|
129 Issue.where(:id => 1).update_all(["assigned_to_id = ?", group.id])
|
Chris@909
|
130
|
Chris@909
|
131 assert group.destroy
|
Chris@909
|
132 assert group.destroyed?
|
Chris@909
|
133
|
Chris@909
|
134 assert_equal nil, Issue.find(1).assigned_to_id
|
Chris@909
|
135 end
|
Chris@0
|
136 end
|