@@ -1,16 +1,16 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
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. |
@@ -23,7 +23,7 class RolesController; def rescue_action(e) raise e end; end | |||
|
23 | 23 | |
|
24 | 24 | class RolesControllerTest < ActionController::TestCase |
|
25 | 25 | fixtures :roles, :users, :members, :member_roles, :workflows, :trackers |
|
26 | ||
|
26 | ||
|
27 | 27 | def setup |
|
28 | 28 | @controller = RolesController.new |
|
29 | 29 | @request = ActionController::TestRequest.new |
@@ -31,7 +31,7 class RolesControllerTest < ActionController::TestCase | |||
|
31 | 31 | User.current = nil |
|
32 | 32 | @request.session[:user_id] = 1 # admin |
|
33 | 33 | end |
|
34 | ||
|
34 | ||
|
35 | 35 | def test_get_index |
|
36 | 36 | get :index |
|
37 | 37 | assert_response :success |
@@ -43,28 +43,28 class RolesControllerTest < ActionController::TestCase | |||
|
43 | 43 | assert_tag :tag => 'a', :attributes => { :href => '/roles/edit/1' }, |
|
44 | 44 | :content => 'Manager' |
|
45 | 45 | end |
|
46 | ||
|
46 | ||
|
47 | 47 | def test_get_new |
|
48 | 48 | get :new |
|
49 | 49 | assert_response :success |
|
50 | 50 | assert_template 'new' |
|
51 | 51 | end |
|
52 | ||
|
52 | ||
|
53 | 53 | def test_post_new_with_validaton_failure |
|
54 | 54 | post :new, :role => {:name => '', |
|
55 | 55 | :permissions => ['add_issues', 'edit_issues', 'log_time', ''], |
|
56 | 56 | :assignable => '0'} |
|
57 | ||
|
57 | ||
|
58 | 58 | assert_response :success |
|
59 | 59 | assert_template 'new' |
|
60 | 60 | assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' } |
|
61 | 61 | end |
|
62 | ||
|
62 | ||
|
63 | 63 | def test_post_new_without_workflow_copy |
|
64 | 64 | post :new, :role => {:name => 'RoleWithoutWorkflowCopy', |
|
65 | 65 | :permissions => ['add_issues', 'edit_issues', 'log_time', ''], |
|
66 | 66 | :assignable => '0'} |
|
67 | ||
|
67 | ||
|
68 | 68 | assert_redirected_to '/roles' |
|
69 | 69 | role = Role.find_by_name('RoleWithoutWorkflowCopy') |
|
70 | 70 | assert_not_nil role |
@@ -77,13 +77,13 class RolesControllerTest < ActionController::TestCase | |||
|
77 | 77 | :permissions => ['add_issues', 'edit_issues', 'log_time', ''], |
|
78 | 78 | :assignable => '0'}, |
|
79 | 79 | :copy_workflow_from => '1' |
|
80 | ||
|
80 | ||
|
81 | 81 | assert_redirected_to '/roles' |
|
82 | 82 | role = Role.find_by_name('RoleWithWorkflowCopy') |
|
83 | 83 | assert_not_nil role |
|
84 | 84 | assert_equal Role.find(1).workflows.size, role.workflows.size |
|
85 | 85 | end |
|
86 | ||
|
86 | ||
|
87 | 87 | def test_get_edit |
|
88 | 88 | get :edit, :id => 1 |
|
89 | 89 | assert_response :success |
@@ -96,62 +96,62 class RolesControllerTest < ActionController::TestCase | |||
|
96 | 96 | :role => {:name => 'Manager', |
|
97 | 97 | :permissions => ['edit_project', ''], |
|
98 | 98 | :assignable => '0'} |
|
99 | ||
|
99 | ||
|
100 | 100 | assert_redirected_to '/roles' |
|
101 | 101 | role = Role.find(1) |
|
102 | 102 | assert_equal [:edit_project], role.permissions |
|
103 | 103 | end |
|
104 | ||
|
104 | ||
|
105 | 105 | def test_destroy |
|
106 | 106 | r = Role.new(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages]) |
|
107 | 107 | assert r.save |
|
108 | ||
|
108 | ||
|
109 | 109 | post :destroy, :id => r |
|
110 | 110 | assert_redirected_to '/roles' |
|
111 | 111 | assert_nil Role.find_by_id(r.id) |
|
112 | 112 | end |
|
113 | ||
|
113 | ||
|
114 | 114 | def test_destroy_role_in_use |
|
115 | 115 | post :destroy, :id => 1 |
|
116 | 116 | assert_redirected_to '/roles' |
|
117 | 117 | assert flash[:error] == 'This role is in use and cannot be deleted.' |
|
118 | 118 | assert_not_nil Role.find_by_id(1) |
|
119 | 119 | end |
|
120 | ||
|
120 | ||
|
121 | 121 | def test_get_report |
|
122 | 122 | get :report |
|
123 | 123 | assert_response :success |
|
124 | 124 | assert_template 'report' |
|
125 | ||
|
125 | ||
|
126 | 126 | assert_not_nil assigns(:roles) |
|
127 | 127 | assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles) |
|
128 | ||
|
128 | ||
|
129 | 129 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
130 | 130 | :name => 'permissions[3][]', |
|
131 | 131 | :value => 'add_issues', |
|
132 | 132 | :checked => 'checked' } |
|
133 | ||
|
133 | ||
|
134 | 134 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
135 | 135 | :name => 'permissions[3][]', |
|
136 | 136 | :value => 'delete_issues', |
|
137 | 137 | :checked => nil } |
|
138 | 138 | end |
|
139 | ||
|
139 | ||
|
140 | 140 | def test_post_report |
|
141 | 141 | post :report, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']} |
|
142 | 142 | assert_redirected_to '/roles' |
|
143 | ||
|
143 | ||
|
144 | 144 | assert_equal [:edit_issues], Role.find(1).permissions |
|
145 | 145 | assert_equal [:add_issues, :delete_issues], Role.find(3).permissions |
|
146 | 146 | assert Role.find(2).permissions.empty? |
|
147 | 147 | end |
|
148 | ||
|
148 | ||
|
149 | 149 | def test_clear_all_permissions |
|
150 | 150 | post :report, :permissions => { '0' => '' } |
|
151 | 151 | assert_redirected_to '/roles' |
|
152 | 152 | assert Role.find(1).permissions.empty? |
|
153 | 153 | end |
|
154 | ||
|
154 | ||
|
155 | 155 | def test_move_highest |
|
156 | 156 | post :edit, :id => 3, :role => {:move_to => 'highest'} |
|
157 | 157 | assert_redirected_to '/roles' |
General Comments 0
You need to be logged in to leave comments.
Login now