@@ -1,87 +1,87 | |||||
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 :all |
|
21 | fixtures :all | |
22 |
|
22 | |||
23 | def test_create |
|
23 | def test_create | |
24 | g = Group.new(:lastname => 'New group') |
|
24 | g = Group.new(:lastname => 'New group') | |
25 | assert g.save |
|
25 | assert g.save | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | def test_roles_given_to_new_user |
|
28 | def test_roles_given_to_new_user | |
29 | group = Group.find(11) |
|
29 | group = Group.find(11) | |
30 | user = User.find(9) |
|
30 | user = User.find(9) | |
31 | project = Project.first |
|
31 | project = Project.first | |
32 |
|
32 | |||
33 | Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) |
|
33 | Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) | |
34 | group.users << user |
|
34 | group.users << user | |
35 | assert user.member_of?(project) |
|
35 | assert user.member_of?(project) | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def test_roles_given_to_existing_user |
|
38 | def test_roles_given_to_existing_user | |
39 | group = Group.find(11) |
|
39 | group = Group.find(11) | |
40 | user = User.find(9) |
|
40 | user = User.find(9) | |
41 | project = Project.first |
|
41 | project = Project.first | |
42 |
|
42 | |||
43 | group.users << user |
|
43 | group.users << user | |
44 | m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) |
|
44 | m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) | |
45 | assert user.member_of?(project) |
|
45 | assert user.member_of?(project) | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_roles_updated |
|
48 | def test_roles_updated | |
49 | group = Group.find(11) |
|
49 | group = Group.find(11) | |
50 | user = User.find(9) |
|
50 | user = User.find(9) | |
51 | project = Project.first |
|
51 | project = Project.first | |
52 | group.users << user |
|
52 | group.users << user | |
53 | m = Member.create!(:principal => group, :project => project, :role_ids => [1]) |
|
53 | m = Member.create!(:principal => group, :project => project, :role_ids => [1]) | |
54 | assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort |
|
54 | assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort | |
55 |
|
55 | |||
56 | m.role_ids = [1, 2] |
|
56 | m.role_ids = [1, 2] | |
57 | assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort |
|
57 | assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort | |
58 |
|
58 | |||
59 | m.role_ids = [2] |
|
59 | m.role_ids = [2] | |
60 | assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort |
|
60 | assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort | |
61 |
|
61 | |||
62 | m.role_ids = [1] |
|
62 | m.role_ids = [1] | |
63 | assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort |
|
63 | assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def test_roles_removed_when_removing_group_membership |
|
66 | def test_roles_removed_when_removing_group_membership | |
67 | assert User.find(8).member_of?(Project.find(5)) |
|
67 | assert User.find(8).member_of?(Project.find(5)) | |
68 | Member.find_by_project_id_and_user_id(5, 10).destroy |
|
68 | Member.find_by_project_id_and_user_id(5, 10).destroy | |
69 | assert !User.find(8).member_of?(Project.find(5)) |
|
69 | assert !User.find(8).member_of?(Project.find(5)) | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def test_roles_removed_when_removing_user_from_group |
|
72 | def test_roles_removed_when_removing_user_from_group | |
73 | assert User.find(8).member_of?(Project.find(5)) |
|
73 | assert User.find(8).member_of?(Project.find(5)) | |
74 | User.find(8).groups.clear |
|
74 | User.find(8).groups.clear | |
75 | assert !User.find(8).member_of?(Project.find(5)) |
|
75 | assert !User.find(8).member_of?(Project.find(5)) | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def test_destroy_should_unassign_issues |
|
78 | def test_destroy_should_unassign_issues | |
79 | group = Group.first |
|
79 | group = Group.first | |
80 | Issue.update_all(["assigned_to_id = ?", group.id], 'id = 1') |
|
80 | Issue.update_all(["assigned_to_id = ?", group.id], 'id = 1') | |
81 |
|
81 | |||
82 | assert group.destroy |
|
82 | assert group.destroy | |
83 | assert group.destroyed? |
|
83 | assert group.destroyed? | |
84 |
|
84 | |||
85 | assert_equal nil, Issue.find(1).assigned_to_id |
|
85 | assert_equal nil, Issue.find(1).assigned_to_id | |
86 | end |
|
86 | end | |
87 | end |
|
87 | end |
General Comments 0
You need to be logged in to leave comments.
Login now