User groups branch merged.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2869 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2009-09-12 08:36:46 +00:00
parent 847c7367b4
commit 7707457145
47 changed files with 920 additions and 90 deletions
+5
View File
@@ -0,0 +1,5 @@
---
groups_users_001:
group_id: 10
user_id: 8
+18 -2
View File
@@ -19,5 +19,21 @@ member_roles_005:
id: 5
role_id: 1
member_id: 5
member_roles_006:
id: 6
role_id: 1
member_id: 6
member_roles_007:
id: 7
role_id: 2
member_id: 6
member_roles_008:
id: 8
role_id: 1
member_id: 7
inherited_from: 6
member_roles_009:
id: 9
role_id: 2
member_id: 7
inherited_from: 7
+12
View File
@@ -30,4 +30,16 @@ members_005:
project_id: 5
user_id: 2
mail_notification: true
members_006:
id: 6
created_on: 2006-07-19 19:35:33 +02:00
project_id: 5
user_id: 10
mail_notification: false
members_007:
id: 7
created_on: 2006-07-19 19:35:33 +02:00
project_id: 5
user_id: 8
mail_notification: false
+8
View File
@@ -144,5 +144,13 @@ users_009:
mail_notification: false
login: miscuser9
type: User
groups_010:
id: 10
lastname: A Team
type: Group
groups_011:
id: 11
lastname: B Team
type: Group
+107
View File
@@ -0,0 +1,107 @@
# Redmine - project management software
# Copyright (C) 2006-2009 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 '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 :projects, :users, :members, :member_roles
def setup
@controller = GroupsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
User.current = nil
@request.session[:user_id] = 1
end
def test_index
get :index
assert_response :success
assert_template 'index'
end
def test_show
get :show, :id => 10
assert_response :success
assert_template 'show'
end
def test_new
get :new
assert_response :success
assert_template 'new'
end
def test_create
assert_difference 'Group.count' do
post :create, :group => {:lastname => 'New group'}
end
assert_redirected_to 'groups'
end
def test_edit
get :edit, :id => 10
assert_response :success
assert_template 'edit'
end
def test_update
post :update, :id => 10
assert_redirected_to 'groups'
end
def test_destroy
assert_difference 'Group.count', -1 do
post :destroy, :id => 10
end
assert_redirected_to 'groups'
end
def test_add_users
assert_difference 'Group.find(10).users.count', 2 do
post :add_users, :id => 10, :user_ids => ['2', '3']
end
end
def test_remove_user
assert_difference 'Group.find(10).users.count', -1 do
post :remove_user, :id => 10, :user_id => '8'
end
end
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
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
def test_destroy_membership
assert_difference 'Group.find(10).members.count', -1 do
post :destroy_membership, :id => 10, :membership_id => 6
end
end
end
+5 -12
View File
@@ -48,14 +48,6 @@ class MembersControllerTest < Test::Unit::TestCase
assert User.find(7).member_of?(Project.find(1))
end
def test_create_by_user_login
assert_difference 'Member.count' do
post :new, :id => 1, :member => {:role_ids => [1], :user_login => 'someone'}
end
assert_redirected_to '/projects/ecookbook/settings/members'
assert User.find(7).member_of?(Project.find(1))
end
def test_create_multiple
assert_difference 'Member.count', 3 do
post :new, :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]}
@@ -79,11 +71,12 @@ class MembersControllerTest < Test::Unit::TestCase
assert !User.find(3).member_of?(Project.find(1))
end
def test_autocomplete_for_member_login
get :autocomplete_for_member_login, :id => 1, :user => 'mis'
def test_autocomplete_for_member
get :autocomplete_for_member, :id => 1, :q => 'mis'
assert_response :success
assert_template 'autocomplete_for_member_login'
assert_template 'autocomplete_for_member'
assert_tag :ul, :child => {:tag => 'li', :content => /miscuser8/}
assert_tag :label, :content => /User Misc/,
:child => { :tag => 'input', :attributes => { :name => 'member[user_ids][]', :value => '8' } }
end
end
+4 -3
View File
@@ -18,7 +18,7 @@
require "#{File.dirname(__FILE__)}/../test_helper"
class AdminTest < ActionController::IntegrationTest
fixtures :users
fixtures :all
def test_add_user
log_user("admin", "admin")
@@ -26,16 +26,17 @@ class AdminTest < ActionController::IntegrationTest
assert_response :success
assert_template "users/add"
post "/users/add", :user => { :login => "psmith", :firstname => "Paul", :lastname => "Smith", :mail => "psmith@somenet.foo", :language => "en" }, :password => "psmith09", :password_confirmation => "psmith09"
assert_redirected_to "/users"
user = User.find_by_login("psmith")
assert_kind_of User, user
assert_redirected_to "/users/#{ user.id }/edit"
logged_user = User.try_to_login("psmith", "psmith09")
assert_kind_of User, logged_user
assert_equal "Paul", logged_user.firstname
post "users/edit", :id => user.id, :user => { :status => User::STATUS_LOCKED }
assert_redirected_to "/users"
assert_redirected_to "/users/#{ user.id }/edit"
locked_user = User.try_to_login("psmith", "psmith09")
assert_equal nil, locked_user
end
+77
View File
@@ -0,0 +1,77 @@
# Redmine - project management software
# Copyright (C) 2006-2009 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'
class GroupTest < Test::Unit::TestCase
fixtures :all
def test_create
g = Group.new(:lastname => 'New group')
assert g.save
end
def test_roles_given_to_new_user
group = Group.find(11)
user = User.find(9)
project = Project.first
Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
group.users << user
assert user.member_of?(project)
end
def test_roles_given_to_existing_user
group = Group.find(11)
user = User.find(9)
project = Project.first
group.users << user
m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
assert user.member_of?(project)
end
def test_roles_updated
group = Group.find(11)
user = User.find(9)
project = Project.first
group.users << user
m = Member.create!(:principal => group, :project => project, :role_ids => [1])
assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort
m.role_ids = [1, 2]
assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort
m.role_ids = [2]
assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort
m.role_ids = [1]
assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort
end
def test_roles_removed_when_removing_group_membership
assert User.find(8).member_of?(Project.find(5))
Member.find_by_project_id_and_user_id(5, 10).destroy
assert !User.find(8).member_of?(Project.find(5))
end
def test_roles_removed_when_removing_user_from_group
assert User.find(8).member_of?(Project.find(5))
User.find(8).groups.clear
assert !User.find(8).member_of?(Project.find(5))
end
end
+12
View File
@@ -63,6 +63,18 @@ class ProjectTest < Test::Unit::TestCase
end
end
def test_members_should_be_active_users
Project.all.each do |project|
assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) }
end
end
def test_users_should_be_active_users
Project.all.each do |project|
assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) }
end
end
def test_archive
user = @ecookbook.members.first.user
@ecookbook.archive