@@ -1,136 +1,136 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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, |
|
22 | :enumerations, :users, | |
23 | :projects_trackers, |
|
23 | :projects_trackers, | |
24 | :roles, |
|
24 | :roles, | |
25 | :member_roles, |
|
25 | :member_roles, | |
26 | :members, |
|
26 | :members, | |
27 | :groups_users |
|
27 | :groups_users | |
28 |
|
28 | |||
29 | include Redmine::I18n |
|
29 | include Redmine::I18n | |
30 |
|
30 | |||
31 | def test_create |
|
31 | def test_create | |
32 | g = Group.new(:name => 'New group') |
|
32 | g = Group.new(:name => 'New group') | |
33 | assert g.save |
|
33 | assert g.save | |
34 | g.reload |
|
34 | g.reload | |
35 | assert_equal 'New group', g.name |
|
35 | assert_equal 'New group', g.name | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def test_name_should_accept_255_characters |
|
38 | def test_name_should_accept_255_characters | |
39 | name = 'a' * 255 |
|
39 | name = 'a' * 255 | |
40 | g = Group.new(:name => name) |
|
40 | g = Group.new(:name => name) | |
41 | assert g.save |
|
41 | assert g.save | |
42 | g.reload |
|
42 | g.reload | |
43 | assert_equal name, g.name |
|
43 | assert_equal name, g.name | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def test_blank_name_error_message |
|
46 | def test_blank_name_error_message | |
47 | set_language_if_valid 'en' |
|
47 | set_language_if_valid 'en' | |
48 | g = Group.new |
|
48 | g = Group.new | |
49 | assert !g.save |
|
49 | assert !g.save | |
50 | assert_include "Name can't be blank", g.errors.full_messages |
|
50 | assert_include "Name can't be blank", g.errors.full_messages | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def test_blank_name_error_message_fr |
|
53 | def test_blank_name_error_message_fr | |
54 | set_language_if_valid 'fr' |
|
54 | set_language_if_valid 'fr' | |
55 | str = "Nom doit \xc3\xaatre renseign\xc3\xa9(e)" |
|
55 | str = "Nom doit \xc3\xaatre renseign\xc3\xa9(e)" | |
56 | str.force_encoding('UTF-8') if str.respond_to?(:force_encoding) |
|
56 | str.force_encoding('UTF-8') if str.respond_to?(:force_encoding) | |
57 | g = Group.new |
|
57 | g = Group.new | |
58 | assert !g.save |
|
58 | assert !g.save | |
59 | assert_include str, g.errors.full_messages |
|
59 | assert_include str, g.errors.full_messages | |
60 | end |
|
60 | end | |
61 |
|
61 | |||
62 | def test_group_roles_should_be_given_to_added_user |
|
62 | def test_group_roles_should_be_given_to_added_user | |
63 | group = Group.find(11) |
|
63 | group = Group.find(11) | |
64 | user = User.find(9) |
|
64 | user = User.find(9) | |
65 | project = Project.first |
|
65 | project = Project.first | |
66 |
|
66 | |||
67 | Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) |
|
67 | Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) | |
68 | group.users << user |
|
68 | group.users << user | |
69 | assert user.member_of?(project) |
|
69 | assert user.member_of?(project) | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def test_new_roles_should_be_given_to_existing_user |
|
72 | def test_new_roles_should_be_given_to_existing_user | |
73 | group = Group.find(11) |
|
73 | group = Group.find(11) | |
74 | user = User.find(9) |
|
74 | user = User.find(9) | |
75 | project = Project.first |
|
75 | project = Project.first | |
76 |
|
76 | |||
77 | group.users << user |
|
77 | group.users << user | |
78 | m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) |
|
78 | m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) | |
79 | assert user.member_of?(project) |
|
79 | assert user.member_of?(project) | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | def test_user_roles_should_updated_when_updating_user_ids |
|
82 | def test_user_roles_should_updated_when_updating_user_ids | |
83 | group = Group.find(11) |
|
83 | group = Group.find(11) | |
84 | user = User.find(9) |
|
84 | user = User.find(9) | |
85 | project = Project.first |
|
85 | project = Project.first | |
86 |
|
86 | |||
87 | Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) |
|
87 | Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) | |
88 | group.user_ids = [user.id] |
|
88 | group.user_ids = [user.id] | |
89 | group.save! |
|
89 | group.save! | |
90 | assert User.find(9).member_of?(project) |
|
90 | assert User.find(9).member_of?(project) | |
91 |
|
91 | |||
92 | group.user_ids = [1] |
|
92 | group.user_ids = [1] | |
93 | group.save! |
|
93 | group.save! | |
94 | assert !User.find(9).member_of?(project) |
|
94 | assert !User.find(9).member_of?(project) | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | def test_user_roles_should_updated_when_updating_group_roles |
|
97 | def test_user_roles_should_updated_when_updating_group_roles | |
98 | group = Group.find(11) |
|
98 | group = Group.find(11) | |
99 | user = User.find(9) |
|
99 | user = User.find(9) | |
100 | project = Project.first |
|
100 | project = Project.first | |
101 | group.users << user |
|
101 | group.users << user | |
102 | m = Member.create!(:principal => group, :project => project, :role_ids => [1]) |
|
102 | m = Member.create!(:principal => group, :project => project, :role_ids => [1]) | |
103 | assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort |
|
103 | assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort | |
104 |
|
104 | |||
105 | m.role_ids = [1, 2] |
|
105 | m.role_ids = [1, 2] | |
106 | assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort |
|
106 | assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort | |
107 |
|
107 | |||
108 | m.role_ids = [2] |
|
108 | m.role_ids = [2] | |
109 | assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort |
|
109 | assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort | |
110 |
|
110 | |||
111 | m.role_ids = [1] |
|
111 | m.role_ids = [1] | |
112 | assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort |
|
112 | assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def test_user_memberships_should_be_removed_when_removing_group_membership |
|
115 | def test_user_memberships_should_be_removed_when_removing_group_membership | |
116 | assert User.find(8).member_of?(Project.find(5)) |
|
116 | assert User.find(8).member_of?(Project.find(5)) | |
117 | Member.find_by_project_id_and_user_id(5, 10).destroy |
|
117 | Member.find_by_project_id_and_user_id(5, 10).destroy | |
118 | assert !User.find(8).member_of?(Project.find(5)) |
|
118 | assert !User.find(8).member_of?(Project.find(5)) | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def test_user_roles_should_be_removed_when_removing_user_from_group |
|
121 | def test_user_roles_should_be_removed_when_removing_user_from_group | |
122 | assert User.find(8).member_of?(Project.find(5)) |
|
122 | assert User.find(8).member_of?(Project.find(5)) | |
123 | User.find(8).groups = [] |
|
123 | User.find(8).groups = [] | |
124 | assert !User.find(8).member_of?(Project.find(5)) |
|
124 | assert !User.find(8).member_of?(Project.find(5)) | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | def test_destroy_should_unassign_issues |
|
127 | def test_destroy_should_unassign_issues | |
128 | group = Group.first |
|
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 | assert group.destroy |
|
131 | assert group.destroy | |
132 | assert group.destroyed? |
|
132 | assert group.destroyed? | |
133 |
|
133 | |||
134 | assert_equal nil, Issue.find(1).assigned_to_id |
|
134 | assert_equal nil, Issue.find(1).assigned_to_id | |
135 | end |
|
135 | end | |
136 | end |
|
136 | end |
General Comments 0
You need to be logged in to leave comments.
Login now