annotate .svn/pristine/56/56704f7daca6d78375b66cf72eeaa2ff41f9c20d.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-2012 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 GroupsControllerTest < ActionController::TestCase
Chris@1295 21 fixtures :projects, :users, :members, :member_roles, :roles, :groups_users
Chris@1295 22
Chris@1295 23 def setup
Chris@1295 24 @request.session[:user_id] = 1
Chris@1295 25 end
Chris@1295 26
Chris@1295 27 def test_index
Chris@1295 28 get :index
Chris@1295 29 assert_response :success
Chris@1295 30 assert_template 'index'
Chris@1295 31 end
Chris@1295 32
Chris@1295 33 def test_show
Chris@1295 34 get :show, :id => 10
Chris@1295 35 assert_response :success
Chris@1295 36 assert_template 'show'
Chris@1295 37 end
Chris@1295 38
Chris@1295 39 def test_show_invalid_should_return_404
Chris@1295 40 get :show, :id => 99
Chris@1295 41 assert_response 404
Chris@1295 42 end
Chris@1295 43
Chris@1295 44 def test_new
Chris@1295 45 get :new
Chris@1295 46 assert_response :success
Chris@1295 47 assert_template 'new'
Chris@1295 48 assert_select 'input[name=?]', 'group[name]'
Chris@1295 49 end
Chris@1295 50
Chris@1295 51 def test_create
Chris@1295 52 assert_difference 'Group.count' do
Chris@1295 53 post :create, :group => {:name => 'New group'}
Chris@1295 54 end
Chris@1295 55 assert_redirected_to '/groups'
Chris@1295 56 group = Group.first(:order => 'id DESC')
Chris@1295 57 assert_equal 'New group', group.name
Chris@1295 58 assert_equal [], group.users
Chris@1295 59 end
Chris@1295 60
Chris@1295 61 def test_create_and_continue
Chris@1295 62 assert_difference 'Group.count' do
Chris@1295 63 post :create, :group => {:name => 'New group'}, :continue => 'Create and continue'
Chris@1295 64 end
Chris@1295 65 assert_redirected_to '/groups/new'
Chris@1295 66 group = Group.first(:order => 'id DESC')
Chris@1295 67 assert_equal 'New group', group.name
Chris@1295 68 end
Chris@1295 69
Chris@1295 70 def test_create_with_failure
Chris@1295 71 assert_no_difference 'Group.count' do
Chris@1295 72 post :create, :group => {:name => ''}
Chris@1295 73 end
Chris@1295 74 assert_response :success
Chris@1295 75 assert_template 'new'
Chris@1295 76 end
Chris@1295 77
Chris@1295 78 def test_edit
Chris@1295 79 get :edit, :id => 10
Chris@1295 80 assert_response :success
Chris@1295 81 assert_template 'edit'
Chris@1295 82 assert_tag 'div', :attributes => {:id => 'tab-content-users'}
Chris@1295 83 assert_tag 'div', :attributes => {:id => 'tab-content-memberships'}
Chris@1295 84 end
Chris@1295 85
Chris@1295 86 def test_update
Chris@1295 87 new_name = 'New name'
Chris@1295 88 put :update, :id => 10, :group => {:name => new_name}
Chris@1295 89 assert_redirected_to '/groups'
Chris@1295 90 group = Group.find(10)
Chris@1295 91 assert_equal new_name, group.name
Chris@1295 92 end
Chris@1295 93
Chris@1295 94 def test_update_with_failure
Chris@1295 95 put :update, :id => 10, :group => {:name => ''}
Chris@1295 96 assert_response :success
Chris@1295 97 assert_template 'edit'
Chris@1295 98 end
Chris@1295 99
Chris@1295 100 def test_destroy
Chris@1295 101 assert_difference 'Group.count', -1 do
Chris@1295 102 post :destroy, :id => 10
Chris@1295 103 end
Chris@1295 104 assert_redirected_to '/groups'
Chris@1295 105 end
Chris@1295 106
Chris@1295 107 def test_add_users
Chris@1295 108 assert_difference 'Group.find(10).users.count', 2 do
Chris@1295 109 post :add_users, :id => 10, :user_ids => ['2', '3']
Chris@1295 110 end
Chris@1295 111 end
Chris@1295 112
Chris@1295 113 def test_xhr_add_users
Chris@1295 114 assert_difference 'Group.find(10).users.count', 2 do
Chris@1295 115 xhr :post, :add_users, :id => 10, :user_ids => ['2', '3']
Chris@1295 116 assert_response :success
Chris@1295 117 assert_template 'add_users'
Chris@1295 118 assert_equal 'text/javascript', response.content_type
Chris@1295 119 end
Chris@1295 120 assert_match /John Smith/, response.body
Chris@1295 121 end
Chris@1295 122
Chris@1295 123 def test_remove_user
Chris@1295 124 assert_difference 'Group.find(10).users.count', -1 do
Chris@1295 125 delete :remove_user, :id => 10, :user_id => '8'
Chris@1295 126 end
Chris@1295 127 end
Chris@1295 128
Chris@1295 129 def test_xhr_remove_user
Chris@1295 130 assert_difference 'Group.find(10).users.count', -1 do
Chris@1295 131 xhr :delete, :remove_user, :id => 10, :user_id => '8'
Chris@1295 132 assert_response :success
Chris@1295 133 assert_template 'remove_user'
Chris@1295 134 assert_equal 'text/javascript', response.content_type
Chris@1295 135 end
Chris@1295 136 end
Chris@1295 137
Chris@1295 138 def test_new_membership
Chris@1295 139 assert_difference 'Group.find(10).members.count' do
Chris@1295 140 post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
Chris@1295 141 end
Chris@1295 142 end
Chris@1295 143
Chris@1295 144 def test_xhr_new_membership
Chris@1295 145 assert_difference 'Group.find(10).members.count' do
Chris@1295 146 xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
Chris@1295 147 assert_response :success
Chris@1295 148 assert_template 'edit_membership'
Chris@1295 149 assert_equal 'text/javascript', response.content_type
Chris@1295 150 end
Chris@1295 151 assert_match /OnlineStore/, response.body
Chris@1295 152 end
Chris@1295 153
Chris@1295 154 def test_xhr_new_membership_with_failure
Chris@1295 155 assert_no_difference 'Group.find(10).members.count' do
Chris@1295 156 xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']}
Chris@1295 157 assert_response :success
Chris@1295 158 assert_template 'edit_membership'
Chris@1295 159 assert_equal 'text/javascript', response.content_type
Chris@1295 160 end
Chris@1295 161 assert_match /alert/, response.body, "Alert message not sent"
Chris@1295 162 end
Chris@1295 163
Chris@1295 164 def test_edit_membership
Chris@1295 165 assert_no_difference 'Group.find(10).members.count' do
Chris@1295 166 post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
Chris@1295 167 end
Chris@1295 168 end
Chris@1295 169
Chris@1295 170 def test_xhr_edit_membership
Chris@1295 171 assert_no_difference 'Group.find(10).members.count' do
Chris@1295 172 xhr :post, :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
Chris@1295 173 assert_response :success
Chris@1295 174 assert_template 'edit_membership'
Chris@1295 175 assert_equal 'text/javascript', response.content_type
Chris@1295 176 end
Chris@1295 177 end
Chris@1295 178
Chris@1295 179 def test_destroy_membership
Chris@1295 180 assert_difference 'Group.find(10).members.count', -1 do
Chris@1295 181 post :destroy_membership, :id => 10, :membership_id => 6
Chris@1295 182 end
Chris@1295 183 end
Chris@1295 184
Chris@1295 185 def test_xhr_destroy_membership
Chris@1295 186 assert_difference 'Group.find(10).members.count', -1 do
Chris@1295 187 xhr :post, :destroy_membership, :id => 10, :membership_id => 6
Chris@1295 188 assert_response :success
Chris@1295 189 assert_template 'destroy_membership'
Chris@1295 190 assert_equal 'text/javascript', response.content_type
Chris@1295 191 end
Chris@1295 192 end
Chris@1295 193
Chris@1295 194 def test_autocomplete_for_user
Chris@1295 195 get :autocomplete_for_user, :id => 10, :q => 'mis'
Chris@1295 196 assert_response :success
Chris@1295 197 users = assigns(:users)
Chris@1295 198 assert_not_nil users
Chris@1295 199 assert users.any?
Chris@1295 200 assert !users.include?(Group.find(10).users.first)
Chris@1295 201 end
Chris@1295 202 end