annotate .svn/pristine/35/35e7528b96f6bca4ea96cc9fa52b687ed6909cb9.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1296 19
Chris@1296 20 class RolesControllerTest < ActionController::TestCase
Chris@1296 21 fixtures :roles, :users, :members, :member_roles, :workflows, :trackers
Chris@1296 22
Chris@1296 23 def setup
Chris@1296 24 @controller = RolesController.new
Chris@1296 25 @request = ActionController::TestRequest.new
Chris@1296 26 @response = ActionController::TestResponse.new
Chris@1296 27 User.current = nil
Chris@1296 28 @request.session[:user_id] = 1 # admin
Chris@1296 29 end
Chris@1296 30
Chris@1296 31 def test_index
Chris@1296 32 get :index
Chris@1296 33 assert_response :success
Chris@1296 34 assert_template 'index'
Chris@1296 35
Chris@1296 36 assert_not_nil assigns(:roles)
Chris@1296 37 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
Chris@1296 38
Chris@1296 39 assert_tag :tag => 'a', :attributes => { :href => '/roles/1/edit' },
Chris@1296 40 :content => 'Manager'
Chris@1296 41 end
Chris@1296 42
Chris@1296 43 def test_new
Chris@1296 44 get :new
Chris@1296 45 assert_response :success
Chris@1296 46 assert_template 'new'
Chris@1296 47 end
Chris@1296 48
Chris@1296 49 def test_new_with_copy
Chris@1296 50 copy_from = Role.find(2)
Chris@1296 51
Chris@1296 52 get :new, :copy => copy_from.id.to_s
Chris@1296 53 assert_response :success
Chris@1296 54 assert_template 'new'
Chris@1296 55
Chris@1296 56 role = assigns(:role)
Chris@1296 57 assert_equal copy_from.permissions, role.permissions
Chris@1296 58
Chris@1296 59 assert_select 'form' do
Chris@1296 60 # blank name
Chris@1296 61 assert_select 'input[name=?][value=]', 'role[name]'
Chris@1296 62 # edit_project permission checked
Chris@1296 63 assert_select 'input[type=checkbox][name=?][value=edit_project][checked=checked]', 'role[permissions][]'
Chris@1296 64 # add_project permission not checked
Chris@1296 65 assert_select 'input[type=checkbox][name=?][value=add_project]', 'role[permissions][]'
Chris@1296 66 assert_select 'input[type=checkbox][name=?][value=add_project][checked=checked]', 'role[permissions][]', 0
Chris@1296 67 # workflow copy selected
Chris@1296 68 assert_select 'select[name=?]', 'copy_workflow_from' do
Chris@1296 69 assert_select 'option[value=2][selected=selected]'
Chris@1296 70 end
Chris@1296 71 end
Chris@1296 72 end
Chris@1296 73
Chris@1296 74 def test_create_with_validaton_failure
Chris@1296 75 post :create, :role => {:name => '',
Chris@1296 76 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
Chris@1296 77 :assignable => '0'}
Chris@1296 78
Chris@1296 79 assert_response :success
Chris@1296 80 assert_template 'new'
Chris@1296 81 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }
Chris@1296 82 end
Chris@1296 83
Chris@1296 84 def test_create_without_workflow_copy
Chris@1296 85 post :create, :role => {:name => 'RoleWithoutWorkflowCopy',
Chris@1296 86 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
Chris@1296 87 :assignable => '0'}
Chris@1296 88
Chris@1296 89 assert_redirected_to '/roles'
Chris@1296 90 role = Role.find_by_name('RoleWithoutWorkflowCopy')
Chris@1296 91 assert_not_nil role
Chris@1296 92 assert_equal [:add_issues, :edit_issues, :log_time], role.permissions
Chris@1296 93 assert !role.assignable?
Chris@1296 94 end
Chris@1296 95
Chris@1296 96 def test_create_with_workflow_copy
Chris@1296 97 post :create, :role => {:name => 'RoleWithWorkflowCopy',
Chris@1296 98 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
Chris@1296 99 :assignable => '0'},
Chris@1296 100 :copy_workflow_from => '1'
Chris@1296 101
Chris@1296 102 assert_redirected_to '/roles'
Chris@1296 103 role = Role.find_by_name('RoleWithWorkflowCopy')
Chris@1296 104 assert_not_nil role
Chris@1296 105 assert_equal Role.find(1).workflow_rules.size, role.workflow_rules.size
Chris@1296 106 end
Chris@1296 107
Chris@1296 108 def test_edit
Chris@1296 109 get :edit, :id => 1
Chris@1296 110 assert_response :success
Chris@1296 111 assert_template 'edit'
Chris@1296 112 assert_equal Role.find(1), assigns(:role)
Chris@1296 113 assert_select 'select[name=?]', 'role[issues_visibility]'
Chris@1296 114 end
Chris@1296 115
Chris@1296 116 def test_edit_anonymous
Chris@1296 117 get :edit, :id => Role.anonymous.id
Chris@1296 118 assert_response :success
Chris@1296 119 assert_template 'edit'
Chris@1296 120 assert_select 'select[name=?]', 'role[issues_visibility]', 0
Chris@1296 121 end
Chris@1296 122
Chris@1296 123 def test_edit_invalid_should_respond_with_404
Chris@1296 124 get :edit, :id => 999
Chris@1296 125 assert_response 404
Chris@1296 126 end
Chris@1296 127
Chris@1296 128 def test_update
Chris@1296 129 put :update, :id => 1,
Chris@1296 130 :role => {:name => 'Manager',
Chris@1296 131 :permissions => ['edit_project', ''],
Chris@1296 132 :assignable => '0'}
Chris@1296 133
Chris@1296 134 assert_redirected_to '/roles'
Chris@1296 135 role = Role.find(1)
Chris@1296 136 assert_equal [:edit_project], role.permissions
Chris@1296 137 end
Chris@1296 138
Chris@1296 139 def test_update_with_failure
Chris@1296 140 put :update, :id => 1, :role => {:name => ''}
Chris@1296 141 assert_response :success
Chris@1296 142 assert_template 'edit'
Chris@1296 143 end
Chris@1296 144
Chris@1296 145 def test_destroy
Chris@1296 146 r = Role.create!(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages])
Chris@1296 147
Chris@1296 148 delete :destroy, :id => r
Chris@1296 149 assert_redirected_to '/roles'
Chris@1296 150 assert_nil Role.find_by_id(r.id)
Chris@1296 151 end
Chris@1296 152
Chris@1296 153 def test_destroy_role_in_use
Chris@1296 154 delete :destroy, :id => 1
Chris@1296 155 assert_redirected_to '/roles'
Chris@1296 156 assert_equal 'This role is in use and cannot be deleted.', flash[:error]
Chris@1296 157 assert_not_nil Role.find_by_id(1)
Chris@1296 158 end
Chris@1296 159
Chris@1296 160 def test_get_permissions
Chris@1296 161 get :permissions
Chris@1296 162 assert_response :success
Chris@1296 163 assert_template 'permissions'
Chris@1296 164
Chris@1296 165 assert_not_nil assigns(:roles)
Chris@1296 166 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
Chris@1296 167
Chris@1296 168 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
Chris@1296 169 :name => 'permissions[3][]',
Chris@1296 170 :value => 'add_issues',
Chris@1296 171 :checked => 'checked' }
Chris@1296 172
Chris@1296 173 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
Chris@1296 174 :name => 'permissions[3][]',
Chris@1296 175 :value => 'delete_issues',
Chris@1296 176 :checked => nil }
Chris@1296 177 end
Chris@1296 178
Chris@1296 179 def test_post_permissions
Chris@1296 180 post :permissions, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']}
Chris@1296 181 assert_redirected_to '/roles'
Chris@1296 182
Chris@1296 183 assert_equal [:edit_issues], Role.find(1).permissions
Chris@1296 184 assert_equal [:add_issues, :delete_issues], Role.find(3).permissions
Chris@1296 185 assert Role.find(2).permissions.empty?
Chris@1296 186 end
Chris@1296 187
Chris@1296 188 def test_clear_all_permissions
Chris@1296 189 post :permissions, :permissions => { '0' => '' }
Chris@1296 190 assert_redirected_to '/roles'
Chris@1296 191 assert Role.find(1).permissions.empty?
Chris@1296 192 end
Chris@1296 193
Chris@1296 194 def test_move_highest
Chris@1296 195 put :update, :id => 3, :role => {:move_to => 'highest'}
Chris@1296 196 assert_redirected_to '/roles'
Chris@1296 197 assert_equal 1, Role.find(3).position
Chris@1296 198 end
Chris@1296 199
Chris@1296 200 def test_move_higher
Chris@1296 201 position = Role.find(3).position
Chris@1296 202 put :update, :id => 3, :role => {:move_to => 'higher'}
Chris@1296 203 assert_redirected_to '/roles'
Chris@1296 204 assert_equal position - 1, Role.find(3).position
Chris@1296 205 end
Chris@1296 206
Chris@1296 207 def test_move_lower
Chris@1296 208 position = Role.find(2).position
Chris@1296 209 put :update, :id => 2, :role => {:move_to => 'lower'}
Chris@1296 210 assert_redirected_to '/roles'
Chris@1296 211 assert_equal position + 1, Role.find(2).position
Chris@1296 212 end
Chris@1296 213
Chris@1296 214 def test_move_lowest
Chris@1296 215 put :update, :id => 2, :role => {:move_to => 'lowest'}
Chris@1296 216 assert_redirected_to '/roles'
Chris@1296 217 assert_equal Role.count, Role.find(2).position
Chris@1296 218 end
Chris@1296 219 end