Chris@909
|
1 # Redmine - project management software
|
Chris@909
|
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@909
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@909
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@119
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19 require 'roles_controller'
|
Chris@0
|
20
|
Chris@0
|
21 # Re-raise errors caught by the controller.
|
Chris@0
|
22 class RolesController; def rescue_action(e) raise e end; end
|
Chris@0
|
23
|
Chris@0
|
24 class RolesControllerTest < ActionController::TestCase
|
Chris@441
|
25 fixtures :roles, :users, :members, :member_roles, :workflows, :trackers
|
Chris@909
|
26
|
Chris@0
|
27 def setup
|
Chris@0
|
28 @controller = RolesController.new
|
Chris@0
|
29 @request = ActionController::TestRequest.new
|
Chris@0
|
30 @response = ActionController::TestResponse.new
|
Chris@0
|
31 User.current = nil
|
Chris@0
|
32 @request.session[:user_id] = 1 # admin
|
Chris@0
|
33 end
|
Chris@909
|
34
|
Chris@0
|
35 def test_get_index
|
Chris@0
|
36 get :index
|
Chris@0
|
37 assert_response :success
|
Chris@0
|
38 assert_template 'index'
|
Chris@0
|
39
|
Chris@0
|
40 assert_not_nil assigns(:roles)
|
Chris@0
|
41 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
|
Chris@0
|
42
|
Chris@0
|
43 assert_tag :tag => 'a', :attributes => { :href => '/roles/edit/1' },
|
Chris@0
|
44 :content => 'Manager'
|
Chris@0
|
45 end
|
Chris@909
|
46
|
Chris@0
|
47 def test_get_new
|
Chris@0
|
48 get :new
|
Chris@0
|
49 assert_response :success
|
Chris@0
|
50 assert_template 'new'
|
Chris@0
|
51 end
|
Chris@909
|
52
|
Chris@0
|
53 def test_post_new_with_validaton_failure
|
Chris@0
|
54 post :new, :role => {:name => '',
|
Chris@0
|
55 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
|
Chris@0
|
56 :assignable => '0'}
|
Chris@909
|
57
|
Chris@0
|
58 assert_response :success
|
Chris@0
|
59 assert_template 'new'
|
Chris@0
|
60 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }
|
Chris@0
|
61 end
|
Chris@909
|
62
|
Chris@0
|
63 def test_post_new_without_workflow_copy
|
Chris@0
|
64 post :new, :role => {:name => 'RoleWithoutWorkflowCopy',
|
Chris@0
|
65 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
|
Chris@0
|
66 :assignable => '0'}
|
Chris@909
|
67
|
chris@37
|
68 assert_redirected_to '/roles'
|
Chris@0
|
69 role = Role.find_by_name('RoleWithoutWorkflowCopy')
|
Chris@0
|
70 assert_not_nil role
|
Chris@0
|
71 assert_equal [:add_issues, :edit_issues, :log_time], role.permissions
|
Chris@0
|
72 assert !role.assignable?
|
Chris@0
|
73 end
|
Chris@0
|
74
|
Chris@0
|
75 def test_post_new_with_workflow_copy
|
Chris@0
|
76 post :new, :role => {:name => 'RoleWithWorkflowCopy',
|
Chris@0
|
77 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
|
Chris@0
|
78 :assignable => '0'},
|
Chris@0
|
79 :copy_workflow_from => '1'
|
Chris@909
|
80
|
chris@37
|
81 assert_redirected_to '/roles'
|
Chris@0
|
82 role = Role.find_by_name('RoleWithWorkflowCopy')
|
Chris@0
|
83 assert_not_nil role
|
Chris@0
|
84 assert_equal Role.find(1).workflows.size, role.workflows.size
|
Chris@0
|
85 end
|
Chris@909
|
86
|
Chris@0
|
87 def test_get_edit
|
Chris@0
|
88 get :edit, :id => 1
|
Chris@0
|
89 assert_response :success
|
Chris@0
|
90 assert_template 'edit'
|
Chris@0
|
91 assert_equal Role.find(1), assigns(:role)
|
Chris@0
|
92 end
|
Chris@0
|
93
|
Chris@0
|
94 def test_post_edit
|
Chris@0
|
95 post :edit, :id => 1,
|
Chris@0
|
96 :role => {:name => 'Manager',
|
Chris@0
|
97 :permissions => ['edit_project', ''],
|
Chris@0
|
98 :assignable => '0'}
|
Chris@909
|
99
|
chris@37
|
100 assert_redirected_to '/roles'
|
Chris@0
|
101 role = Role.find(1)
|
Chris@0
|
102 assert_equal [:edit_project], role.permissions
|
Chris@0
|
103 end
|
Chris@909
|
104
|
Chris@0
|
105 def test_destroy
|
Chris@0
|
106 r = Role.new(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages])
|
Chris@0
|
107 assert r.save
|
Chris@909
|
108
|
Chris@0
|
109 post :destroy, :id => r
|
chris@37
|
110 assert_redirected_to '/roles'
|
Chris@0
|
111 assert_nil Role.find_by_id(r.id)
|
Chris@0
|
112 end
|
Chris@909
|
113
|
Chris@0
|
114 def test_destroy_role_in_use
|
Chris@0
|
115 post :destroy, :id => 1
|
chris@37
|
116 assert_redirected_to '/roles'
|
Chris@441
|
117 assert flash[:error] == 'This role is in use and cannot be deleted.'
|
Chris@0
|
118 assert_not_nil Role.find_by_id(1)
|
Chris@0
|
119 end
|
Chris@909
|
120
|
Chris@0
|
121 def test_get_report
|
Chris@0
|
122 get :report
|
Chris@0
|
123 assert_response :success
|
Chris@0
|
124 assert_template 'report'
|
Chris@909
|
125
|
Chris@0
|
126 assert_not_nil assigns(:roles)
|
Chris@0
|
127 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
|
Chris@909
|
128
|
Chris@0
|
129 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
Chris@0
|
130 :name => 'permissions[3][]',
|
Chris@0
|
131 :value => 'add_issues',
|
Chris@0
|
132 :checked => 'checked' }
|
Chris@909
|
133
|
Chris@0
|
134 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
Chris@0
|
135 :name => 'permissions[3][]',
|
Chris@0
|
136 :value => 'delete_issues',
|
Chris@0
|
137 :checked => nil }
|
Chris@0
|
138 end
|
Chris@909
|
139
|
Chris@0
|
140 def test_post_report
|
Chris@0
|
141 post :report, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']}
|
chris@37
|
142 assert_redirected_to '/roles'
|
Chris@909
|
143
|
Chris@0
|
144 assert_equal [:edit_issues], Role.find(1).permissions
|
Chris@0
|
145 assert_equal [:add_issues, :delete_issues], Role.find(3).permissions
|
Chris@0
|
146 assert Role.find(2).permissions.empty?
|
Chris@0
|
147 end
|
Chris@909
|
148
|
Chris@0
|
149 def test_clear_all_permissions
|
Chris@0
|
150 post :report, :permissions => { '0' => '' }
|
chris@37
|
151 assert_redirected_to '/roles'
|
Chris@0
|
152 assert Role.find(1).permissions.empty?
|
Chris@0
|
153 end
|
Chris@909
|
154
|
Chris@0
|
155 def test_move_highest
|
Chris@0
|
156 post :edit, :id => 3, :role => {:move_to => 'highest'}
|
chris@37
|
157 assert_redirected_to '/roles'
|
Chris@0
|
158 assert_equal 1, Role.find(3).position
|
Chris@0
|
159 end
|
Chris@0
|
160
|
Chris@0
|
161 def test_move_higher
|
Chris@0
|
162 position = Role.find(3).position
|
Chris@0
|
163 post :edit, :id => 3, :role => {:move_to => 'higher'}
|
chris@37
|
164 assert_redirected_to '/roles'
|
Chris@0
|
165 assert_equal position - 1, Role.find(3).position
|
Chris@0
|
166 end
|
Chris@0
|
167
|
Chris@0
|
168 def test_move_lower
|
Chris@0
|
169 position = Role.find(2).position
|
Chris@0
|
170 post :edit, :id => 2, :role => {:move_to => 'lower'}
|
chris@37
|
171 assert_redirected_to '/roles'
|
Chris@0
|
172 assert_equal position + 1, Role.find(2).position
|
Chris@0
|
173 end
|
Chris@0
|
174
|
Chris@0
|
175 def test_move_lowest
|
Chris@0
|
176 post :edit, :id => 2, :role => {:move_to => 'lowest'}
|
chris@37
|
177 assert_redirected_to '/roles'
|
Chris@0
|
178 assert_equal Role.count, Role.find(2).position
|
Chris@0
|
179 end
|
Chris@0
|
180 end
|