2009-09-12 12:36:46 +04:00
|
|
|
# Redmine - project management software
|
2013-01-12 13:29:31 +04:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2009-09-12 12:36:46 +04:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-09-01 03:00:24 +04:00
|
|
|
#
|
2009-09-12 12:36:46 +04:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-09-01 03:00:24 +04:00
|
|
|
#
|
2009-09-12 12:36:46 +04:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2010-12-13 02:24:34 +03:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2009-09-12 12:36:46 +04:00
|
|
|
|
2009-09-13 21:14:35 +04:00
|
|
|
class GroupsControllerTest < ActionController::TestCase
|
2012-11-01 15:58:45 +04:00
|
|
|
fixtures :projects, :users, :members, :member_roles, :roles, :groups_users
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def setup
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def test_index
|
|
|
|
get :index
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'index'
|
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def test_show
|
|
|
|
get :show, :id => 10
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'show'
|
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2012-07-15 23:05:34 +04:00
|
|
|
def test_show_invalid_should_return_404
|
|
|
|
get :show, :id => 99
|
|
|
|
assert_response 404
|
|
|
|
end
|
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def test_new
|
|
|
|
get :new
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'new'
|
2012-06-01 22:24:33 +04:00
|
|
|
assert_select 'input[name=?]', 'group[name]'
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def test_create
|
|
|
|
assert_difference 'Group.count' do
|
2012-06-01 22:24:33 +04:00
|
|
|
post :create, :group => {:name => 'New group'}
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
2010-11-14 19:45:32 +03:00
|
|
|
assert_redirected_to '/groups'
|
2014-01-08 08:32:16 +04:00
|
|
|
group = Group.order('id DESC').first
|
2011-11-28 21:46:21 +04:00
|
|
|
assert_equal 'New group', group.name
|
|
|
|
assert_equal [], group.users
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2011-07-21 19:55:50 +04:00
|
|
|
def test_create_and_continue
|
|
|
|
assert_difference 'Group.count' do
|
2012-06-01 22:24:33 +04:00
|
|
|
post :create, :group => {:name => 'New group'}, :continue => 'Create and continue'
|
2011-07-21 19:55:50 +04:00
|
|
|
end
|
|
|
|
assert_redirected_to '/groups/new'
|
2014-01-08 08:32:16 +04:00
|
|
|
group = Group.order('id DESC').first
|
2011-11-28 21:46:21 +04:00
|
|
|
assert_equal 'New group', group.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_create_with_failure
|
|
|
|
assert_no_difference 'Group.count' do
|
2012-06-01 22:24:33 +04:00
|
|
|
post :create, :group => {:name => ''}
|
2011-11-28 21:46:21 +04:00
|
|
|
end
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'new'
|
2011-07-21 19:55:50 +04:00
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def test_edit
|
|
|
|
get :edit, :id => 10
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'edit'
|
2013-01-14 21:40:51 +04:00
|
|
|
|
|
|
|
assert_select 'div#tab-content-users'
|
|
|
|
assert_select 'div#tab-content-memberships' do
|
|
|
|
assert_select 'a', :text => 'Private child of eCookbook'
|
|
|
|
end
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def test_update
|
2011-11-28 21:46:21 +04:00
|
|
|
new_name = 'New name'
|
2012-06-01 22:24:33 +04:00
|
|
|
put :update, :id => 10, :group => {:name => new_name}
|
2010-11-14 19:45:32 +03:00
|
|
|
assert_redirected_to '/groups'
|
2011-11-28 21:46:21 +04:00
|
|
|
group = Group.find(10)
|
|
|
|
assert_equal new_name, group.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_update_with_failure
|
2012-06-01 22:24:33 +04:00
|
|
|
put :update, :id => 10, :group => {:name => ''}
|
2011-11-28 21:46:21 +04:00
|
|
|
assert_response :success
|
|
|
|
assert_template 'edit'
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def test_destroy
|
|
|
|
assert_difference 'Group.count', -1 do
|
|
|
|
post :destroy, :id => 10
|
|
|
|
end
|
2010-11-14 19:45:32 +03:00
|
|
|
assert_redirected_to '/groups'
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def test_add_users
|
|
|
|
assert_difference 'Group.find(10).users.count', 2 do
|
|
|
|
post :add_users, :id => 10, :user_ids => ['2', '3']
|
|
|
|
end
|
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2011-11-30 00:21:54 +04:00
|
|
|
def test_xhr_add_users
|
|
|
|
assert_difference 'Group.find(10).users.count', 2 do
|
|
|
|
xhr :post, :add_users, :id => 10, :user_ids => ['2', '3']
|
2012-07-19 20:57:59 +04:00
|
|
|
assert_response :success
|
|
|
|
assert_template 'add_users'
|
|
|
|
assert_equal 'text/javascript', response.content_type
|
2011-11-30 00:21:54 +04:00
|
|
|
end
|
2012-07-19 20:57:59 +04:00
|
|
|
assert_match /John Smith/, response.body
|
2011-11-30 00:21:54 +04:00
|
|
|
end
|
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def test_remove_user
|
|
|
|
assert_difference 'Group.find(10).users.count', -1 do
|
2011-11-27 14:47:36 +04:00
|
|
|
delete :remove_user, :id => 10, :user_id => '8'
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2011-11-30 00:21:54 +04:00
|
|
|
def test_xhr_remove_user
|
|
|
|
assert_difference 'Group.find(10).users.count', -1 do
|
|
|
|
xhr :delete, :remove_user, :id => 10, :user_id => '8'
|
2012-07-19 20:57:59 +04:00
|
|
|
assert_response :success
|
|
|
|
assert_template 'remove_user'
|
|
|
|
assert_equal 'text/javascript', response.content_type
|
2011-11-30 00:21:54 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def test_new_membership
|
|
|
|
assert_difference 'Group.find(10).members.count' do
|
|
|
|
post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
|
|
|
|
end
|
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2011-11-30 00:21:54 +04:00
|
|
|
def test_xhr_new_membership
|
|
|
|
assert_difference 'Group.find(10).members.count' do
|
|
|
|
xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
|
2012-07-19 20:57:59 +04:00
|
|
|
assert_response :success
|
|
|
|
assert_template 'edit_membership'
|
|
|
|
assert_equal 'text/javascript', response.content_type
|
2011-11-30 00:21:54 +04:00
|
|
|
end
|
2012-07-19 20:57:59 +04:00
|
|
|
assert_match /OnlineStore/, response.body
|
2011-11-30 00:21:54 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_xhr_new_membership_with_failure
|
|
|
|
assert_no_difference 'Group.find(10).members.count' do
|
|
|
|
xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']}
|
2012-07-19 20:57:59 +04:00
|
|
|
assert_response :success
|
|
|
|
assert_template 'edit_membership'
|
|
|
|
assert_equal 'text/javascript', response.content_type
|
2011-11-30 00:21:54 +04:00
|
|
|
end
|
2012-07-19 20:57:59 +04:00
|
|
|
assert_match /alert/, response.body, "Alert message not sent"
|
2011-11-30 00:21:54 +04:00
|
|
|
end
|
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def test_edit_membership
|
|
|
|
assert_no_difference 'Group.find(10).members.count' do
|
|
|
|
post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
|
|
|
|
end
|
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2012-07-19 20:57:59 +04:00
|
|
|
def test_xhr_edit_membership
|
|
|
|
assert_no_difference 'Group.find(10).members.count' do
|
|
|
|
xhr :post, :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'edit_membership'
|
|
|
|
assert_equal 'text/javascript', response.content_type
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def test_destroy_membership
|
|
|
|
assert_difference 'Group.find(10).members.count', -1 do
|
|
|
|
post :destroy_membership, :id => 10, :membership_id => 6
|
|
|
|
end
|
|
|
|
end
|
2011-09-01 03:00:24 +04:00
|
|
|
|
2011-11-30 00:21:54 +04:00
|
|
|
def test_xhr_destroy_membership
|
|
|
|
assert_difference 'Group.find(10).members.count', -1 do
|
|
|
|
xhr :post, :destroy_membership, :id => 10, :membership_id => 6
|
2012-07-19 20:57:59 +04:00
|
|
|
assert_response :success
|
|
|
|
assert_template 'destroy_membership'
|
|
|
|
assert_equal 'text/javascript', response.content_type
|
2011-11-30 00:21:54 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-01 20:47:30 +04:00
|
|
|
def test_autocomplete_for_user
|
2013-01-18 21:57:16 +04:00
|
|
|
get :autocomplete_for_user, :id => 10, :q => 'smi', :format => 'js'
|
2011-04-01 20:47:30 +04:00
|
|
|
assert_response :success
|
2013-01-18 21:57:16 +04:00
|
|
|
assert_include 'John Smith', response.body
|
2011-04-01 20:47:30 +04:00
|
|
|
end
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|