annotate test/functional/roles_controller_test.rb @ 1524:82fac3dcf466 redmine-2.5-integration

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