annotate .svn/pristine/06/06efa9c81bf4ffa47e3211023e46fcb09d4eac0f.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-2013 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 User.current = nil
Chris@1295 25 @request.session[:user_id] = 1 # admin
Chris@1295 26 end
Chris@1295 27
Chris@1295 28 def test_index
Chris@1295 29 get :index
Chris@1295 30 assert_response :success
Chris@1295 31 assert_template 'index'
Chris@1295 32
Chris@1295 33 assert_not_nil assigns(:roles)
Chris@1295 34 assert_equal Role.order('builtin, position').all, assigns(:roles)
Chris@1295 35
Chris@1295 36 assert_tag :tag => 'a', :attributes => { :href => '/roles/1/edit' },
Chris@1295 37 :content => 'Manager'
Chris@1295 38 end
Chris@1295 39
Chris@1295 40 def test_new
Chris@1295 41 get :new
Chris@1295 42 assert_response :success
Chris@1295 43 assert_template 'new'
Chris@1295 44 end
Chris@1295 45
Chris@1295 46 def test_new_with_copy
Chris@1295 47 copy_from = Role.find(2)
Chris@1295 48
Chris@1295 49 get :new, :copy => copy_from.id.to_s
Chris@1295 50 assert_response :success
Chris@1295 51 assert_template 'new'
Chris@1295 52
Chris@1295 53 role = assigns(:role)
Chris@1295 54 assert_equal copy_from.permissions, role.permissions
Chris@1295 55
Chris@1295 56 assert_select 'form' do
Chris@1295 57 # blank name
Chris@1295 58 assert_select 'input[name=?][value=]', 'role[name]'
Chris@1295 59 # edit_project permission checked
Chris@1295 60 assert_select 'input[type=checkbox][name=?][value=edit_project][checked=checked]', 'role[permissions][]'
Chris@1295 61 # add_project permission not checked
Chris@1295 62 assert_select 'input[type=checkbox][name=?][value=add_project]', 'role[permissions][]'
Chris@1295 63 assert_select 'input[type=checkbox][name=?][value=add_project][checked=checked]', 'role[permissions][]', 0
Chris@1295 64 # workflow copy selected
Chris@1295 65 assert_select 'select[name=?]', 'copy_workflow_from' do
Chris@1295 66 assert_select 'option[value=2][selected=selected]'
Chris@1295 67 end
Chris@1295 68 end
Chris@1295 69 end
Chris@1295 70
Chris@1295 71 def test_create_with_validaton_failure
Chris@1295 72 post :create, :role => {:name => '',
Chris@1295 73 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
Chris@1295 74 :assignable => '0'}
Chris@1295 75
Chris@1295 76 assert_response :success
Chris@1295 77 assert_template 'new'
Chris@1295 78 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }
Chris@1295 79 end
Chris@1295 80
Chris@1295 81 def test_create_without_workflow_copy
Chris@1295 82 post :create, :role => {:name => 'RoleWithoutWorkflowCopy',
Chris@1295 83 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
Chris@1295 84 :assignable => '0'}
Chris@1295 85
Chris@1295 86 assert_redirected_to '/roles'
Chris@1295 87 role = Role.find_by_name('RoleWithoutWorkflowCopy')
Chris@1295 88 assert_not_nil role
Chris@1295 89 assert_equal [:add_issues, :edit_issues, :log_time], role.permissions
Chris@1295 90 assert !role.assignable?
Chris@1295 91 end
Chris@1295 92
Chris@1295 93 def test_create_with_workflow_copy
Chris@1295 94 post :create, :role => {:name => 'RoleWithWorkflowCopy',
Chris@1295 95 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
Chris@1295 96 :assignable => '0'},
Chris@1295 97 :copy_workflow_from => '1'
Chris@1295 98
Chris@1295 99 assert_redirected_to '/roles'
Chris@1295 100 role = Role.find_by_name('RoleWithWorkflowCopy')
Chris@1295 101 assert_not_nil role
Chris@1295 102 assert_equal Role.find(1).workflow_rules.size, role.workflow_rules.size
Chris@1295 103 end
Chris@1295 104
Chris@1295 105 def test_edit
Chris@1295 106 get :edit, :id => 1
Chris@1295 107 assert_response :success
Chris@1295 108 assert_template 'edit'
Chris@1295 109 assert_equal Role.find(1), assigns(:role)
Chris@1295 110 assert_select 'select[name=?]', 'role[issues_visibility]'
Chris@1295 111 end
Chris@1295 112
Chris@1295 113 def test_edit_anonymous
Chris@1295 114 get :edit, :id => Role.anonymous.id
Chris@1295 115 assert_response :success
Chris@1295 116 assert_template 'edit'
Chris@1295 117 assert_select 'select[name=?]', 'role[issues_visibility]', 0
Chris@1295 118 end
Chris@1295 119
Chris@1295 120 def test_edit_invalid_should_respond_with_404
Chris@1295 121 get :edit, :id => 999
Chris@1295 122 assert_response 404
Chris@1295 123 end
Chris@1295 124
Chris@1295 125 def test_update
Chris@1295 126 put :update, :id => 1,
Chris@1295 127 :role => {:name => 'Manager',
Chris@1295 128 :permissions => ['edit_project', ''],
Chris@1295 129 :assignable => '0'}
Chris@1295 130
Chris@1295 131 assert_redirected_to '/roles'
Chris@1295 132 role = Role.find(1)
Chris@1295 133 assert_equal [:edit_project], role.permissions
Chris@1295 134 end
Chris@1295 135
Chris@1295 136 def test_update_with_failure
Chris@1295 137 put :update, :id => 1, :role => {:name => ''}
Chris@1295 138 assert_response :success
Chris@1295 139 assert_template 'edit'
Chris@1295 140 end
Chris@1295 141
Chris@1295 142 def test_destroy
Chris@1295 143 r = Role.create!(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages])
Chris@1295 144
Chris@1295 145 delete :destroy, :id => r
Chris@1295 146 assert_redirected_to '/roles'
Chris@1295 147 assert_nil Role.find_by_id(r.id)
Chris@1295 148 end
Chris@1295 149
Chris@1295 150 def test_destroy_role_in_use
Chris@1295 151 delete :destroy, :id => 1
Chris@1295 152 assert_redirected_to '/roles'
Chris@1295 153 assert_equal 'This role is in use and cannot be deleted.', flash[:error]
Chris@1295 154 assert_not_nil Role.find_by_id(1)
Chris@1295 155 end
Chris@1295 156
Chris@1295 157 def test_get_permissions
Chris@1295 158 get :permissions
Chris@1295 159 assert_response :success
Chris@1295 160 assert_template 'permissions'
Chris@1295 161
Chris@1295 162 assert_not_nil assigns(:roles)
Chris@1295 163 assert_equal Role.order('builtin, position').all, assigns(:roles)
Chris@1295 164
Chris@1295 165 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
Chris@1295 166 :name => 'permissions[3][]',
Chris@1295 167 :value => 'add_issues',
Chris@1295 168 :checked => 'checked' }
Chris@1295 169
Chris@1295 170 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
Chris@1295 171 :name => 'permissions[3][]',
Chris@1295 172 :value => 'delete_issues',
Chris@1295 173 :checked => nil }
Chris@1295 174 end
Chris@1295 175
Chris@1295 176 def test_post_permissions
Chris@1295 177 post :permissions, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']}
Chris@1295 178 assert_redirected_to '/roles'
Chris@1295 179
Chris@1295 180 assert_equal [:edit_issues], Role.find(1).permissions
Chris@1295 181 assert_equal [:add_issues, :delete_issues], Role.find(3).permissions
Chris@1295 182 assert Role.find(2).permissions.empty?
Chris@1295 183 end
Chris@1295 184
Chris@1295 185 def test_clear_all_permissions
Chris@1295 186 post :permissions, :permissions => { '0' => '' }
Chris@1295 187 assert_redirected_to '/roles'
Chris@1295 188 assert Role.find(1).permissions.empty?
Chris@1295 189 end
Chris@1295 190
Chris@1295 191 def test_move_highest
Chris@1295 192 put :update, :id => 3, :role => {:move_to => 'highest'}
Chris@1295 193 assert_redirected_to '/roles'
Chris@1295 194 assert_equal 1, Role.find(3).position
Chris@1295 195 end
Chris@1295 196
Chris@1295 197 def test_move_higher
Chris@1295 198 position = Role.find(3).position
Chris@1295 199 put :update, :id => 3, :role => {:move_to => 'higher'}
Chris@1295 200 assert_redirected_to '/roles'
Chris@1295 201 assert_equal position - 1, Role.find(3).position
Chris@1295 202 end
Chris@1295 203
Chris@1295 204 def test_move_lower
Chris@1295 205 position = Role.find(2).position
Chris@1295 206 put :update, :id => 2, :role => {:move_to => 'lower'}
Chris@1295 207 assert_redirected_to '/roles'
Chris@1295 208 assert_equal position + 1, Role.find(2).position
Chris@1295 209 end
Chris@1295 210
Chris@1295 211 def test_move_lowest
Chris@1295 212 put :update, :id => 2, :role => {:move_to => 'lowest'}
Chris@1295 213 assert_redirected_to '/roles'
Chris@1295 214 assert_equal Role.count, Role.find(2).position
Chris@1295 215 end
Chris@1295 216 end