To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / test / unit / .svn / text-base / group_test.rb.svn-base @ 441:cbce1fd3b1b7
History | View | Annotate | Download (2.54 KB)
| 1 |
# Redmine - project management software |
|---|---|
| 2 |
# Copyright (C) 2006-2009 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 :all |
| 22 |
|
| 23 |
def test_create |
| 24 |
g = Group.new(:lastname => 'New group') |
| 25 |
assert g.save |
| 26 |
end |
| 27 |
|
| 28 |
def test_roles_given_to_new_user |
| 29 |
group = Group.find(11) |
| 30 |
user = User.find(9) |
| 31 |
project = Project.first |
| 32 |
|
| 33 |
Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) |
| 34 |
group.users << user |
| 35 |
assert user.member_of?(project) |
| 36 |
end |
| 37 |
|
| 38 |
def test_roles_given_to_existing_user |
| 39 |
group = Group.find(11) |
| 40 |
user = User.find(9) |
| 41 |
project = Project.first |
| 42 |
|
| 43 |
group.users << user |
| 44 |
m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) |
| 45 |
assert user.member_of?(project) |
| 46 |
end |
| 47 |
|
| 48 |
def test_roles_updated |
| 49 |
group = Group.find(11) |
| 50 |
user = User.find(9) |
| 51 |
project = Project.first |
| 52 |
group.users << user |
| 53 |
m = Member.create!(:principal => group, :project => project, :role_ids => [1]) |
| 54 |
assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort |
| 55 |
|
| 56 |
m.role_ids = [1, 2] |
| 57 |
assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort |
| 58 |
|
| 59 |
m.role_ids = [2] |
| 60 |
assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort |
| 61 |
|
| 62 |
m.role_ids = [1] |
| 63 |
assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort |
| 64 |
end |
| 65 |
|
| 66 |
def test_roles_removed_when_removing_group_membership |
| 67 |
assert User.find(8).member_of?(Project.find(5)) |
| 68 |
Member.find_by_project_id_and_user_id(5, 10).destroy |
| 69 |
assert !User.find(8).member_of?(Project.find(5)) |
| 70 |
end |
| 71 |
|
| 72 |
def test_roles_removed_when_removing_user_from_group |
| 73 |
assert User.find(8).member_of?(Project.find(5)) |
| 74 |
User.find(8).groups.clear |
| 75 |
assert !User.find(8).member_of?(Project.find(5)) |
| 76 |
end |
| 77 |
end |