annotate .svn/pristine/b4/b4ba08d8234f93ee5bdf8cc15661d379cb66b24f.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 cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19 require 'roles_controller'
Chris@909 20
Chris@909 21 # Re-raise errors caught by the controller.
Chris@909 22 class RolesController; def rescue_action(e) raise e end; end
Chris@909 23
Chris@909 24 class RolesControllerTest < ActionController::TestCase
Chris@909 25 fixtures :roles, :users, :members, :member_roles, :workflows, :trackers
Chris@909 26
Chris@909 27 def setup
Chris@909 28 @controller = RolesController.new
Chris@909 29 @request = ActionController::TestRequest.new
Chris@909 30 @response = ActionController::TestResponse.new
Chris@909 31 User.current = nil
Chris@909 32 @request.session[:user_id] = 1 # admin
Chris@909 33 end
Chris@909 34
Chris@909 35 def test_get_index
Chris@909 36 get :index
Chris@909 37 assert_response :success
Chris@909 38 assert_template 'index'
Chris@909 39
Chris@909 40 assert_not_nil assigns(:roles)
Chris@909 41 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
Chris@909 42
Chris@909 43 assert_tag :tag => 'a', :attributes => { :href => '/roles/edit/1' },
Chris@909 44 :content => 'Manager'
Chris@909 45 end
Chris@909 46
Chris@909 47 def test_get_new
Chris@909 48 get :new
Chris@909 49 assert_response :success
Chris@909 50 assert_template 'new'
Chris@909 51 end
Chris@909 52
Chris@909 53 def test_post_new_with_validaton_failure
Chris@909 54 post :new, :role => {:name => '',
Chris@909 55 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
Chris@909 56 :assignable => '0'}
Chris@909 57
Chris@909 58 assert_response :success
Chris@909 59 assert_template 'new'
Chris@909 60 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }
Chris@909 61 end
Chris@909 62
Chris@909 63 def test_post_new_without_workflow_copy
Chris@909 64 post :new, :role => {:name => 'RoleWithoutWorkflowCopy',
Chris@909 65 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
Chris@909 66 :assignable => '0'}
Chris@909 67
Chris@909 68 assert_redirected_to '/roles'
Chris@909 69 role = Role.find_by_name('RoleWithoutWorkflowCopy')
Chris@909 70 assert_not_nil role
Chris@909 71 assert_equal [:add_issues, :edit_issues, :log_time], role.permissions
Chris@909 72 assert !role.assignable?
Chris@909 73 end
Chris@909 74
Chris@909 75 def test_post_new_with_workflow_copy
Chris@909 76 post :new, :role => {:name => 'RoleWithWorkflowCopy',
Chris@909 77 :permissions => ['add_issues', 'edit_issues', 'log_time', ''],
Chris@909 78 :assignable => '0'},
Chris@909 79 :copy_workflow_from => '1'
Chris@909 80
Chris@909 81 assert_redirected_to '/roles'
Chris@909 82 role = Role.find_by_name('RoleWithWorkflowCopy')
Chris@909 83 assert_not_nil role
Chris@909 84 assert_equal Role.find(1).workflows.size, role.workflows.size
Chris@909 85 end
Chris@909 86
Chris@909 87 def test_get_edit
Chris@909 88 get :edit, :id => 1
Chris@909 89 assert_response :success
Chris@909 90 assert_template 'edit'
Chris@909 91 assert_equal Role.find(1), assigns(:role)
Chris@909 92 end
Chris@909 93
Chris@909 94 def test_post_edit
Chris@909 95 post :edit, :id => 1,
Chris@909 96 :role => {:name => 'Manager',
Chris@909 97 :permissions => ['edit_project', ''],
Chris@909 98 :assignable => '0'}
Chris@909 99
Chris@909 100 assert_redirected_to '/roles'
Chris@909 101 role = Role.find(1)
Chris@909 102 assert_equal [:edit_project], role.permissions
Chris@909 103 end
Chris@909 104
Chris@909 105 def test_destroy
Chris@909 106 r = Role.new(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages])
Chris@909 107 assert r.save
Chris@909 108
Chris@909 109 post :destroy, :id => r
Chris@909 110 assert_redirected_to '/roles'
Chris@909 111 assert_nil Role.find_by_id(r.id)
Chris@909 112 end
Chris@909 113
Chris@909 114 def test_destroy_role_in_use
Chris@909 115 post :destroy, :id => 1
Chris@909 116 assert_redirected_to '/roles'
Chris@909 117 assert flash[:error] == 'This role is in use and cannot be deleted.'
Chris@909 118 assert_not_nil Role.find_by_id(1)
Chris@909 119 end
Chris@909 120
Chris@909 121 def test_get_report
Chris@909 122 get :report
Chris@909 123 assert_response :success
Chris@909 124 assert_template 'report'
Chris@909 125
Chris@909 126 assert_not_nil assigns(:roles)
Chris@909 127 assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles)
Chris@909 128
Chris@909 129 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
Chris@909 130 :name => 'permissions[3][]',
Chris@909 131 :value => 'add_issues',
Chris@909 132 :checked => 'checked' }
Chris@909 133
Chris@909 134 assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
Chris@909 135 :name => 'permissions[3][]',
Chris@909 136 :value => 'delete_issues',
Chris@909 137 :checked => nil }
Chris@909 138 end
Chris@909 139
Chris@909 140 def test_post_report
Chris@909 141 post :report, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']}
Chris@909 142 assert_redirected_to '/roles'
Chris@909 143
Chris@909 144 assert_equal [:edit_issues], Role.find(1).permissions
Chris@909 145 assert_equal [:add_issues, :delete_issues], Role.find(3).permissions
Chris@909 146 assert Role.find(2).permissions.empty?
Chris@909 147 end
Chris@909 148
Chris@909 149 def test_clear_all_permissions
Chris@909 150 post :report, :permissions => { '0' => '' }
Chris@909 151 assert_redirected_to '/roles'
Chris@909 152 assert Role.find(1).permissions.empty?
Chris@909 153 end
Chris@909 154
Chris@909 155 def test_move_highest
Chris@909 156 post :edit, :id => 3, :role => {:move_to => 'highest'}
Chris@909 157 assert_redirected_to '/roles'
Chris@909 158 assert_equal 1, Role.find(3).position
Chris@909 159 end
Chris@909 160
Chris@909 161 def test_move_higher
Chris@909 162 position = Role.find(3).position
Chris@909 163 post :edit, :id => 3, :role => {:move_to => 'higher'}
Chris@909 164 assert_redirected_to '/roles'
Chris@909 165 assert_equal position - 1, Role.find(3).position
Chris@909 166 end
Chris@909 167
Chris@909 168 def test_move_lower
Chris@909 169 position = Role.find(2).position
Chris@909 170 post :edit, :id => 2, :role => {:move_to => 'lower'}
Chris@909 171 assert_redirected_to '/roles'
Chris@909 172 assert_equal position + 1, Role.find(2).position
Chris@909 173 end
Chris@909 174
Chris@909 175 def test_move_lowest
Chris@909 176 post :edit, :id => 2, :role => {:move_to => 'lowest'}
Chris@909 177 assert_redirected_to '/roles'
Chris@909 178 assert_equal Role.count, Role.find(2).position
Chris@909 179 end
Chris@909 180 end