annotate .svn/pristine/d8/d86fddb095643a873b39891575c7d6d16d93b882.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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