annotate .svn/pristine/da/da391cc28994d066c2bbb55ae6f4853a48f37175.svn-base @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents
children
rev   line source
Chris@1464 1 # Redmine - project management software
Chris@1464 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1464 3 #
Chris@1464 4 # This program is free software; you can redistribute it and/or
Chris@1464 5 # modify it under the terms of the GNU General Public License
Chris@1464 6 # as published by the Free Software Foundation; either version 2
Chris@1464 7 # of the License, or (at your option) any later version.
Chris@1464 8 #
Chris@1464 9 # This program is distributed in the hope that it will be useful,
Chris@1464 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1464 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1464 12 # GNU General Public License for more details.
Chris@1464 13 #
Chris@1464 14 # You should have received a copy of the GNU General Public License
Chris@1464 15 # along with this program; if not, write to the Free Software
Chris@1464 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1464 17
Chris@1464 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1464 19
Chris@1464 20 class GroupsControllerTest < ActionController::TestCase
Chris@1464 21 fixtures :projects, :users, :members, :member_roles, :roles, :groups_users
Chris@1464 22
Chris@1464 23 def setup
Chris@1464 24 @request.session[:user_id] = 1
Chris@1464 25 end
Chris@1464 26
Chris@1464 27 def test_index
Chris@1464 28 get :index
Chris@1464 29 assert_response :success
Chris@1464 30 assert_template 'index'
Chris@1464 31 end
Chris@1464 32
Chris@1464 33 def test_show
Chris@1464 34 get :show, :id => 10
Chris@1464 35 assert_response :success
Chris@1464 36 assert_template 'show'
Chris@1464 37 end
Chris@1464 38
Chris@1464 39 def test_show_invalid_should_return_404
Chris@1464 40 get :show, :id => 99
Chris@1464 41 assert_response 404
Chris@1464 42 end
Chris@1464 43
Chris@1464 44 def test_new
Chris@1464 45 get :new
Chris@1464 46 assert_response :success
Chris@1464 47 assert_template 'new'
Chris@1464 48 assert_select 'input[name=?]', 'group[name]'
Chris@1464 49 end
Chris@1464 50
Chris@1464 51 def test_create
Chris@1464 52 assert_difference 'Group.count' do
Chris@1464 53 post :create, :group => {:name => 'New group'}
Chris@1464 54 end
Chris@1464 55 assert_redirected_to '/groups'
Chris@1464 56 group = Group.first(:order => 'id DESC')
Chris@1464 57 assert_equal 'New group', group.name
Chris@1464 58 assert_equal [], group.users
Chris@1464 59 end
Chris@1464 60
Chris@1464 61 def test_create_and_continue
Chris@1464 62 assert_difference 'Group.count' do
Chris@1464 63 post :create, :group => {:name => 'New group'}, :continue => 'Create and continue'
Chris@1464 64 end
Chris@1464 65 assert_redirected_to '/groups/new'
Chris@1464 66 group = Group.first(:order => 'id DESC')
Chris@1464 67 assert_equal 'New group', group.name
Chris@1464 68 end
Chris@1464 69
Chris@1464 70 def test_create_with_failure
Chris@1464 71 assert_no_difference 'Group.count' do
Chris@1464 72 post :create, :group => {:name => ''}
Chris@1464 73 end
Chris@1464 74 assert_response :success
Chris@1464 75 assert_template 'new'
Chris@1464 76 end
Chris@1464 77
Chris@1464 78 def test_edit
Chris@1464 79 get :edit, :id => 10
Chris@1464 80 assert_response :success
Chris@1464 81 assert_template 'edit'
Chris@1464 82
Chris@1464 83 assert_select 'div#tab-content-users'
Chris@1464 84 assert_select 'div#tab-content-memberships' do
Chris@1464 85 assert_select 'a', :text => 'Private child of eCookbook'
Chris@1464 86 end
Chris@1464 87 end
Chris@1464 88
Chris@1464 89 def test_update
Chris@1464 90 new_name = 'New name'
Chris@1464 91 put :update, :id => 10, :group => {:name => new_name}
Chris@1464 92 assert_redirected_to '/groups'
Chris@1464 93 group = Group.find(10)
Chris@1464 94 assert_equal new_name, group.name
Chris@1464 95 end
Chris@1464 96
Chris@1464 97 def test_update_with_failure
Chris@1464 98 put :update, :id => 10, :group => {:name => ''}
Chris@1464 99 assert_response :success
Chris@1464 100 assert_template 'edit'
Chris@1464 101 end
Chris@1464 102
Chris@1464 103 def test_destroy
Chris@1464 104 assert_difference 'Group.count', -1 do
Chris@1464 105 post :destroy, :id => 10
Chris@1464 106 end
Chris@1464 107 assert_redirected_to '/groups'
Chris@1464 108 end
Chris@1464 109
Chris@1464 110 def test_add_users
Chris@1464 111 assert_difference 'Group.find(10).users.count', 2 do
Chris@1464 112 post :add_users, :id => 10, :user_ids => ['2', '3']
Chris@1464 113 end
Chris@1464 114 end
Chris@1464 115
Chris@1464 116 def test_xhr_add_users
Chris@1464 117 assert_difference 'Group.find(10).users.count', 2 do
Chris@1464 118 xhr :post, :add_users, :id => 10, :user_ids => ['2', '3']
Chris@1464 119 assert_response :success
Chris@1464 120 assert_template 'add_users'
Chris@1464 121 assert_equal 'text/javascript', response.content_type
Chris@1464 122 end
Chris@1464 123 assert_match /John Smith/, response.body
Chris@1464 124 end
Chris@1464 125
Chris@1464 126 def test_remove_user
Chris@1464 127 assert_difference 'Group.find(10).users.count', -1 do
Chris@1464 128 delete :remove_user, :id => 10, :user_id => '8'
Chris@1464 129 end
Chris@1464 130 end
Chris@1464 131
Chris@1464 132 def test_xhr_remove_user
Chris@1464 133 assert_difference 'Group.find(10).users.count', -1 do
Chris@1464 134 xhr :delete, :remove_user, :id => 10, :user_id => '8'
Chris@1464 135 assert_response :success
Chris@1464 136 assert_template 'remove_user'
Chris@1464 137 assert_equal 'text/javascript', response.content_type
Chris@1464 138 end
Chris@1464 139 end
Chris@1464 140
Chris@1464 141 def test_new_membership
Chris@1464 142 assert_difference 'Group.find(10).members.count' do
Chris@1464 143 post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
Chris@1464 144 end
Chris@1464 145 end
Chris@1464 146
Chris@1464 147 def test_xhr_new_membership
Chris@1464 148 assert_difference 'Group.find(10).members.count' do
Chris@1464 149 xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
Chris@1464 150 assert_response :success
Chris@1464 151 assert_template 'edit_membership'
Chris@1464 152 assert_equal 'text/javascript', response.content_type
Chris@1464 153 end
Chris@1464 154 assert_match /OnlineStore/, response.body
Chris@1464 155 end
Chris@1464 156
Chris@1464 157 def test_xhr_new_membership_with_failure
Chris@1464 158 assert_no_difference 'Group.find(10).members.count' do
Chris@1464 159 xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']}
Chris@1464 160 assert_response :success
Chris@1464 161 assert_template 'edit_membership'
Chris@1464 162 assert_equal 'text/javascript', response.content_type
Chris@1464 163 end
Chris@1464 164 assert_match /alert/, response.body, "Alert message not sent"
Chris@1464 165 end
Chris@1464 166
Chris@1464 167 def test_edit_membership
Chris@1464 168 assert_no_difference 'Group.find(10).members.count' do
Chris@1464 169 post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
Chris@1464 170 end
Chris@1464 171 end
Chris@1464 172
Chris@1464 173 def test_xhr_edit_membership
Chris@1464 174 assert_no_difference 'Group.find(10).members.count' do
Chris@1464 175 xhr :post, :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
Chris@1464 176 assert_response :success
Chris@1464 177 assert_template 'edit_membership'
Chris@1464 178 assert_equal 'text/javascript', response.content_type
Chris@1464 179 end
Chris@1464 180 end
Chris@1464 181
Chris@1464 182 def test_destroy_membership
Chris@1464 183 assert_difference 'Group.find(10).members.count', -1 do
Chris@1464 184 post :destroy_membership, :id => 10, :membership_id => 6
Chris@1464 185 end
Chris@1464 186 end
Chris@1464 187
Chris@1464 188 def test_xhr_destroy_membership
Chris@1464 189 assert_difference 'Group.find(10).members.count', -1 do
Chris@1464 190 xhr :post, :destroy_membership, :id => 10, :membership_id => 6
Chris@1464 191 assert_response :success
Chris@1464 192 assert_template 'destroy_membership'
Chris@1464 193 assert_equal 'text/javascript', response.content_type
Chris@1464 194 end
Chris@1464 195 end
Chris@1464 196
Chris@1464 197 def test_autocomplete_for_user
Chris@1464 198 get :autocomplete_for_user, :id => 10, :q => 'smi', :format => 'js'
Chris@1464 199 assert_response :success
Chris@1464 200 assert_include 'John Smith', response.body
Chris@1464 201 end
Chris@1464 202 end