annotate .svn/pristine/ec/ec3d40d1fc61932cd193e8aa0335b6e83da715b7.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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