annotate .svn/pristine/56/56704f7daca6d78375b66cf72eeaa2ff41f9c20d.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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