@@ -1,111 +1,111 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 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 RoleTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :roles, :workflows |
|
22 | 22 | |
|
23 | 23 | def test_copy_workflows |
|
24 | 24 | source = Role.find(1) |
|
25 | 25 | assert_equal 90, source.workflows.size |
|
26 | ||
|
26 | ||
|
27 | 27 | target = Role.new(:name => 'Target') |
|
28 | 28 | assert target.save |
|
29 | 29 | target.workflows.copy(source) |
|
30 | 30 | target.reload |
|
31 | 31 | assert_equal 90, target.workflows.size |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_add_permission |
|
35 | 35 | role = Role.find(1) |
|
36 | 36 | size = role.permissions.size |
|
37 | 37 | role.add_permission!("apermission", "anotherpermission") |
|
38 | 38 | role.reload |
|
39 | 39 | assert role.permissions.include?(:anotherpermission) |
|
40 | 40 | assert_equal size + 2, role.permissions.size |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | def test_remove_permission |
|
44 | 44 | role = Role.find(1) |
|
45 | 45 | size = role.permissions.size |
|
46 | 46 | perm = role.permissions[0..1] |
|
47 | 47 | role.remove_permission!(*perm) |
|
48 | 48 | role.reload |
|
49 | 49 | assert ! role.permissions.include?(perm[0]) |
|
50 | 50 | assert_equal size - 2, role.permissions.size |
|
51 | 51 | end |
|
52 | ||
|
52 | ||
|
53 | 53 | def test_name |
|
54 | 54 | I18n.locale = 'fr' |
|
55 | 55 | assert_equal 'Manager', Role.find(1).name |
|
56 | 56 | assert_equal 'Anonyme', Role.anonymous.name |
|
57 | 57 | assert_equal 'Non membre', Role.non_member.name |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | context "#anonymous" do |
|
61 | 61 | should "return the anonymous role" do |
|
62 | 62 | role = Role.anonymous |
|
63 | 63 | assert role.builtin? |
|
64 | 64 | assert_equal Role::BUILTIN_ANONYMOUS, role.builtin |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | context "with a missing anonymous role" do |
|
68 | 68 | setup do |
|
69 | 69 | Role.delete_all("builtin = #{Role::BUILTIN_ANONYMOUS}") |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | should "create a new anonymous role" do |
|
73 | 73 | assert_difference('Role.count') do |
|
74 | 74 | Role.anonymous |
|
75 | 75 | end |
|
76 | 76 | end |
|
77 | 77 | |
|
78 | 78 | should "return the anonymous role" do |
|
79 | 79 | role = Role.anonymous |
|
80 | 80 | assert role.builtin? |
|
81 | 81 | assert_equal Role::BUILTIN_ANONYMOUS, role.builtin |
|
82 | 82 | end |
|
83 | 83 | end |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | context "#non_member" do |
|
87 | 87 | should "return the non-member role" do |
|
88 | 88 | role = Role.non_member |
|
89 | 89 | assert role.builtin? |
|
90 | 90 | assert_equal Role::BUILTIN_NON_MEMBER, role.builtin |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | context "with a missing non-member role" do |
|
94 | 94 | setup do |
|
95 | 95 | Role.delete_all("builtin = #{Role::BUILTIN_NON_MEMBER}") |
|
96 | 96 | end |
|
97 | 97 | |
|
98 | 98 | should "create a new non-member role" do |
|
99 | 99 | assert_difference('Role.count') do |
|
100 | 100 | Role.non_member |
|
101 | 101 | end |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | 104 | should "return the non-member role" do |
|
105 | 105 | role = Role.non_member |
|
106 | 106 | assert role.builtin? |
|
107 | 107 | assert_equal Role::BUILTIN_NON_MEMBER, role.builtin |
|
108 | 108 | end |
|
109 | 109 | end |
|
110 | 110 | end |
|
111 | 111 | end |
General Comments 0
You need to be logged in to leave comments.
Login now