2009-09-12 12:36:46 +04:00
|
|
|
# Redmine - project management software
|
2012-05-05 16:56:53 +04:00
|
|
|
# Copyright (C) 2006-2012 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
|
2009-10-29 21:40:00 +03:00
|
|
|
fixtures :projects, :users, :members, :member_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
|
|
|
|
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'
|
2011-11-28 21:46:21 +04:00
|
|
|
group = Group.first(:order => 'id DESC')
|
|
|
|
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'
|
2011-11-28 21:46:21 +04:00
|
|
|
group = Group.first(:order => 'id DESC')
|
|
|
|
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'
|
2011-11-30 00:21:54 +04:00
|
|
|
assert_tag 'div', :attributes => {:id => 'tab-content-users'}
|
|
|
|
assert_tag 'div', :attributes => {:id => 'tab-content-memberships'}
|
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']
|
|
|
|
end
|
|
|
|
assert_select_rjs :replace_html, 'tab-content-users'
|
|
|
|
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'
|
|
|
|
end
|
|
|
|
assert_select_rjs :replace_html, 'tab-content-users'
|
|
|
|
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']}
|
|
|
|
end
|
|
|
|
assert_select_rjs :replace_html, 'tab-content-memberships'
|
|
|
|
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']}
|
|
|
|
end
|
|
|
|
assert @response.body.match(/alert/i), "Alert message not sent"
|
|
|
|
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
|
|
|
|
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
|
|
|
|
end
|
|
|
|
assert_select_rjs :replace_html, 'tab-content-memberships'
|
|
|
|
end
|
|
|
|
|
2011-04-01 20:47:30 +04:00
|
|
|
def test_autocomplete_for_user
|
|
|
|
get :autocomplete_for_user, :id => 10, :q => 'mis'
|
|
|
|
assert_response :success
|
|
|
|
users = assigns(:users)
|
|
|
|
assert_not_nil users
|
|
|
|
assert users.any?
|
|
|
|
assert !users.include?(Group.find(10).users.first)
|
|
|
|
end
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|