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