annotate .svn/pristine/35/35e7528b96f6bca4ea96cc9fa52b687ed6909cb9.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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