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