mirror of
https://github.com/redmine/redmine.git
synced 2026-07-07 17:53:33 +02:00
User groups feature initial commit.
git-svn-id: http://redmine.rubyforge.org/svn/branches/work@1373 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
76
groups/test/functional/groups_controller_test.rb
Normal file
76
groups/test/functional/groups_controller_test.rb
Normal file
@@ -0,0 +1,76 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2008 FreeCode
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'groups_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class GroupsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class GroupsControllerTest < Test::Unit::TestCase
|
||||
fixtures :groups, :users
|
||||
|
||||
def setup
|
||||
@controller = GroupsController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
@request.session[:user_id] = 1 # admin
|
||||
end
|
||||
|
||||
def test_should_get_index
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_not_nil assigns(:groups)
|
||||
end
|
||||
|
||||
def test_should_get_new
|
||||
get :new
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_should_create_group
|
||||
assert_difference('Group.count') do
|
||||
post :create, :group => { :name => 'New group' }
|
||||
end
|
||||
assert_redirected_to groups_path
|
||||
assert_not_nil Group.find_by_name('New group')
|
||||
end
|
||||
|
||||
def test_should_show_group
|
||||
get :show, :id => 1
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_should_get_edit
|
||||
get :edit, :id => 1
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_should_update_group
|
||||
put :update, :id => 1, :group => { :name => 'Renamed' }
|
||||
assert_redirected_to groups_path
|
||||
assert_equal 'Renamed', Group.find(1).name
|
||||
end
|
||||
|
||||
def test_should_destroy_group
|
||||
assert_difference('Group.count', -1) do
|
||||
delete :destroy, :id => 1
|
||||
end
|
||||
assert_redirected_to groups_path
|
||||
end
|
||||
end
|
||||
80
groups/test/functional/members_controller_test.rb
Normal file
80
groups/test/functional/members_controller_test.rb
Normal file
@@ -0,0 +1,80 @@
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2008 Jean-Philippe Lang
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'members_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class MembersController; def rescue_action(e) raise e end; end
|
||||
|
||||
class MembersControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :roles, :users, :groups, :members
|
||||
|
||||
def setup
|
||||
@controller = MembersController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
User.current = nil
|
||||
@request.session[:user_id] = 1 # admin
|
||||
end
|
||||
|
||||
def test_should_create_user_member
|
||||
p = Project.find(1)
|
||||
u = users(:new_client)
|
||||
assert_difference('Member.count') do
|
||||
post :new, :id => p.id, :member => { :role_id => roles(:reporter).id }, :principal => "user_#{u.id}"
|
||||
end
|
||||
assert_redirected_to :controller => 'projects', :action => 'settings', :id => p, :tab => 'members'
|
||||
assert u.reload.member_of?(p)
|
||||
assert_equal roles(:reporter), u.role_for_project(p)
|
||||
end
|
||||
|
||||
def test_should_create_group_member
|
||||
p = Project.find(2)
|
||||
assert_difference('Member.count') do
|
||||
post :new, :id => p.id, :member => { :role_id => roles(:reporter) }, :principal => 'group_1'
|
||||
end
|
||||
assert_redirected_to :controller => 'projects', :action => 'settings', :id => p, :tab => 'members'
|
||||
end
|
||||
|
||||
def test_should_update_user_member
|
||||
u = User.find(3)
|
||||
p = Project.find(1)
|
||||
assert_equal roles(:developer), u.role_for_project(p)
|
||||
assert_difference('Member.count', 0) do
|
||||
post :edit, :id => 2, :member => { :role_id => roles(:manager).id }
|
||||
end
|
||||
assert_redirected_to :controller => 'projects', :action => 'settings', :id => p, :tab => 'members'
|
||||
assert_equal roles(:manager), u.reload.role_for_project(p)
|
||||
end
|
||||
|
||||
def test_should_destroy
|
||||
p = Project.find(1)
|
||||
assert_difference('Member.count', -1) do
|
||||
post :destroy, :id => 2
|
||||
end
|
||||
assert_redirected_to :controller => 'projects', :action => 'settings', :id => p, :tab => 'members'
|
||||
end
|
||||
|
||||
def test_should_not_destroy_inherited_membership
|
||||
p = Project.find(1)
|
||||
assert_difference('Member.count', 0) do
|
||||
post :destroy, :id => 6
|
||||
end
|
||||
assert_response 404
|
||||
end
|
||||
end
|
||||
@@ -47,6 +47,14 @@ class UsersControllerTest < Test::Unit::TestCase
|
||||
assert_nil assigns(:users).detect {|u| !u.active?}
|
||||
end
|
||||
|
||||
def test_should_add_membership
|
||||
assert_difference('User.find(2).memberships.count') do
|
||||
post :edit_membership, :id => 2, :membership => { :role_id => 1, :project_id => 3 }
|
||||
assert_redirected_to 'users/edit/2'
|
||||
assert User.find(2).member_of?(Project.find(3))
|
||||
end
|
||||
end
|
||||
|
||||
def test_edit_membership
|
||||
post :edit_membership, :id => 2, :membership_id => 1,
|
||||
:membership => { :role_id => 2}
|
||||
|
||||
Reference in New Issue
Block a user