annotate test/functional/groups_controller_test.rb @ 1466:834828a14f2b bug_598

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