annotate test/functional/groups_controller_test.rb @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents e248c7af89ec
children dffacf8a6908
rev   line source
Chris@0 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 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@1464 82
Chris@1464 83 assert_select 'div#tab-content-users'
Chris@1464 84 assert_select 'div#tab-content-memberships' do
Chris@1464 85 assert_select 'a', :text => 'Private child of eCookbook'
Chris@1464 86 end
Chris@0 87 end
Chris@909 88
Chris@0 89 def test_update
Chris@909 90 new_name = 'New name'
Chris@1115 91 put :update, :id => 10, :group => {:name => new_name}
chris@37 92 assert_redirected_to '/groups'
Chris@909 93 group = Group.find(10)
Chris@909 94 assert_equal new_name, group.name
Chris@0 95 end
Chris@909 96
Chris@909 97 def test_update_with_failure
Chris@1115 98 put :update, :id => 10, :group => {:name => ''}
Chris@909 99 assert_response :success
Chris@909 100 assert_template 'edit'
Chris@909 101 end
Chris@909 102
Chris@0 103 def test_destroy
Chris@0 104 assert_difference 'Group.count', -1 do
Chris@0 105 post :destroy, :id => 10
Chris@0 106 end
chris@37 107 assert_redirected_to '/groups'
Chris@0 108 end
Chris@909 109
Chris@0 110 def test_add_users
Chris@0 111 assert_difference 'Group.find(10).users.count', 2 do
Chris@0 112 post :add_users, :id => 10, :user_ids => ['2', '3']
Chris@0 113 end
Chris@0 114 end
Chris@909 115
Chris@909 116 def test_xhr_add_users
Chris@909 117 assert_difference 'Group.find(10).users.count', 2 do
Chris@909 118 xhr :post, :add_users, :id => 10, :user_ids => ['2', '3']
Chris@1115 119 assert_response :success
Chris@1115 120 assert_template 'add_users'
Chris@1115 121 assert_equal 'text/javascript', response.content_type
Chris@909 122 end
Chris@1115 123 assert_match /John Smith/, response.body
Chris@909 124 end
Chris@909 125
Chris@0 126 def test_remove_user
Chris@0 127 assert_difference 'Group.find(10).users.count', -1 do
Chris@909 128 delete :remove_user, :id => 10, :user_id => '8'
Chris@0 129 end
Chris@0 130 end
Chris@909 131
Chris@909 132 def test_xhr_remove_user
Chris@909 133 assert_difference 'Group.find(10).users.count', -1 do
Chris@909 134 xhr :delete, :remove_user, :id => 10, :user_id => '8'
Chris@1115 135 assert_response :success
Chris@1115 136 assert_template 'remove_user'
Chris@1115 137 assert_equal 'text/javascript', response.content_type
Chris@909 138 end
Chris@909 139 end
Chris@909 140
Chris@0 141 def test_new_membership
Chris@0 142 assert_difference 'Group.find(10).members.count' do
Chris@0 143 post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
Chris@0 144 end
Chris@0 145 end
Chris@909 146
Chris@909 147 def test_xhr_new_membership
Chris@909 148 assert_difference 'Group.find(10).members.count' do
Chris@909 149 xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
Chris@1115 150 assert_response :success
Chris@1115 151 assert_template 'edit_membership'
Chris@1115 152 assert_equal 'text/javascript', response.content_type
Chris@909 153 end
Chris@1115 154 assert_match /OnlineStore/, response.body
Chris@909 155 end
Chris@909 156
Chris@909 157 def test_xhr_new_membership_with_failure
Chris@909 158 assert_no_difference 'Group.find(10).members.count' do
Chris@909 159 xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']}
Chris@1115 160 assert_response :success
Chris@1115 161 assert_template 'edit_membership'
Chris@1115 162 assert_equal 'text/javascript', response.content_type
Chris@909 163 end
Chris@1115 164 assert_match /alert/, response.body, "Alert message not sent"
Chris@909 165 end
Chris@909 166
Chris@0 167 def test_edit_membership
Chris@0 168 assert_no_difference 'Group.find(10).members.count' do
Chris@0 169 post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
Chris@0 170 end
Chris@0 171 end
Chris@909 172
Chris@1115 173 def test_xhr_edit_membership
Chris@1115 174 assert_no_difference 'Group.find(10).members.count' do
Chris@1115 175 xhr :post, :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
Chris@1115 176 assert_response :success
Chris@1115 177 assert_template 'edit_membership'
Chris@1115 178 assert_equal 'text/javascript', response.content_type
Chris@1115 179 end
Chris@1115 180 end
Chris@1115 181
Chris@0 182 def test_destroy_membership
Chris@0 183 assert_difference 'Group.find(10).members.count', -1 do
Chris@0 184 post :destroy_membership, :id => 10, :membership_id => 6
Chris@0 185 end
Chris@0 186 end
Chris@909 187
Chris@909 188 def test_xhr_destroy_membership
Chris@909 189 assert_difference 'Group.find(10).members.count', -1 do
Chris@909 190 xhr :post, :destroy_membership, :id => 10, :membership_id => 6
Chris@1115 191 assert_response :success
Chris@1115 192 assert_template 'destroy_membership'
Chris@1115 193 assert_equal 'text/javascript', response.content_type
Chris@909 194 end
Chris@909 195 end
Chris@909 196
Chris@441 197 def test_autocomplete_for_user
Chris@1464 198 get :autocomplete_for_user, :id => 10, :q => 'smi', :format => 'js'
Chris@441 199 assert_response :success
Chris@1464 200 assert_include 'John Smith', response.body
Chris@441 201 end
Chris@0 202 end