annotate .svn/pristine/cf/cf33cf57a3e921509ff6e96342de19ecb5f2697c.svn-base @ 1628:9c5f8e24dadc live tip

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