To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / ae / ae670d8528dae7894b350a3933e33244d75d0910.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (3.48 KB)
| 1 |
# Redmine - project management software |
|---|---|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or |
| 5 |
# modify it under the terms of the GNU General Public License |
| 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 |
# of the License, or (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program; if not, write to the Free Software |
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
|
| 18 |
require File.expand_path('../../test_helper', __FILE__)
|
| 19 |
|
| 20 |
class GroupTest < ActiveSupport::TestCase |
| 21 |
fixtures :projects, :trackers, :issue_statuses, :issues, |
| 22 |
:enumerations, :users, :issue_categories, |
| 23 |
:projects_trackers, |
| 24 |
:roles, |
| 25 |
:member_roles, |
| 26 |
:members, |
| 27 |
:enabled_modules, |
| 28 |
:workflows, |
| 29 |
:groups_users |
| 30 |
|
| 31 |
include Redmine::I18n |
| 32 |
|
| 33 |
def test_create |
| 34 |
g = Group.new(:lastname => 'New group') |
| 35 |
assert g.save |
| 36 |
end |
| 37 |
|
| 38 |
def test_blank_name_error_message |
| 39 |
set_language_if_valid 'en' |
| 40 |
g = Group.new |
| 41 |
assert !g.save |
| 42 |
assert_include "Name can't be blank", g.errors.full_messages |
| 43 |
end |
| 44 |
|
| 45 |
def test_blank_name_error_message_fr |
| 46 |
set_language_if_valid 'fr' |
| 47 |
str = "Nom doit \xc3\xaatre renseign\xc3\xa9(e)" |
| 48 |
str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
|
| 49 |
g = Group.new |
| 50 |
assert !g.save |
| 51 |
assert_include str, g.errors.full_messages |
| 52 |
end |
| 53 |
|
| 54 |
def test_roles_given_to_new_user |
| 55 |
group = Group.find(11) |
| 56 |
user = User.find(9) |
| 57 |
project = Project.first |
| 58 |
|
| 59 |
Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) |
| 60 |
group.users << user |
| 61 |
assert user.member_of?(project) |
| 62 |
end |
| 63 |
|
| 64 |
def test_roles_given_to_existing_user |
| 65 |
group = Group.find(11) |
| 66 |
user = User.find(9) |
| 67 |
project = Project.first |
| 68 |
|
| 69 |
group.users << user |
| 70 |
m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) |
| 71 |
assert user.member_of?(project) |
| 72 |
end |
| 73 |
|
| 74 |
def test_roles_updated |
| 75 |
group = Group.find(11) |
| 76 |
user = User.find(9) |
| 77 |
project = Project.first |
| 78 |
group.users << user |
| 79 |
m = Member.create!(:principal => group, :project => project, :role_ids => [1]) |
| 80 |
assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort |
| 81 |
|
| 82 |
m.role_ids = [1, 2] |
| 83 |
assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort |
| 84 |
|
| 85 |
m.role_ids = [2] |
| 86 |
assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort |
| 87 |
|
| 88 |
m.role_ids = [1] |
| 89 |
assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort |
| 90 |
end |
| 91 |
|
| 92 |
def test_roles_removed_when_removing_group_membership |
| 93 |
assert User.find(8).member_of?(Project.find(5)) |
| 94 |
Member.find_by_project_id_and_user_id(5, 10).destroy |
| 95 |
assert !User.find(8).member_of?(Project.find(5)) |
| 96 |
end |
| 97 |
|
| 98 |
def test_roles_removed_when_removing_user_from_group |
| 99 |
assert User.find(8).member_of?(Project.find(5)) |
| 100 |
User.find(8).groups.clear |
| 101 |
assert !User.find(8).member_of?(Project.find(5)) |
| 102 |
end |
| 103 |
|
| 104 |
def test_destroy_should_unassign_issues |
| 105 |
group = Group.first |
| 106 |
Issue.update_all(["assigned_to_id = ?", group.id], 'id = 1') |
| 107 |
|
| 108 |
assert group.destroy |
| 109 |
assert group.destroyed? |
| 110 |
|
| 111 |
assert_equal nil, Issue.find(1).assigned_to_id |
| 112 |
end |
| 113 |
end |