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