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 / 63 / 6360196bfabbf1ba6bec0417e53823e42158b575.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (4.03 KB)
| 1 | 1296:038ba2d95de8 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2012 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(:name => 'New group') |
||
| 35 | assert g.save |
||
| 36 | g.reload |
||
| 37 | assert_equal 'New group', g.name |
||
| 38 | end |
||
| 39 | |||
| 40 | def test_blank_name_error_message |
||
| 41 | set_language_if_valid 'en' |
||
| 42 | g = Group.new |
||
| 43 | assert !g.save |
||
| 44 | assert_include "Name can't be blank", g.errors.full_messages |
||
| 45 | end |
||
| 46 | |||
| 47 | def test_blank_name_error_message_fr |
||
| 48 | set_language_if_valid 'fr' |
||
| 49 | str = "Nom doit \xc3\xaatre renseign\xc3\xa9(e)" |
||
| 50 | str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
|
||
| 51 | g = Group.new |
||
| 52 | assert !g.save |
||
| 53 | assert_include str, g.errors.full_messages |
||
| 54 | end |
||
| 55 | |||
| 56 | def test_group_roles_should_be_given_to_added_user |
||
| 57 | group = Group.find(11) |
||
| 58 | user = User.find(9) |
||
| 59 | project = Project.first |
||
| 60 | |||
| 61 | Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) |
||
| 62 | group.users << user |
||
| 63 | assert user.member_of?(project) |
||
| 64 | end |
||
| 65 | |||
| 66 | def test_new_roles_should_be_given_to_existing_user |
||
| 67 | group = Group.find(11) |
||
| 68 | user = User.find(9) |
||
| 69 | project = Project.first |
||
| 70 | |||
| 71 | group.users << user |
||
| 72 | m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) |
||
| 73 | assert user.member_of?(project) |
||
| 74 | end |
||
| 75 | |||
| 76 | def test_user_roles_should_updated_when_updating_user_ids |
||
| 77 | group = Group.find(11) |
||
| 78 | user = User.find(9) |
||
| 79 | project = Project.first |
||
| 80 | |||
| 81 | Member.create!(:principal => group, :project => project, :role_ids => [1, 2]) |
||
| 82 | group.user_ids = [user.id] |
||
| 83 | group.save! |
||
| 84 | assert User.find(9).member_of?(project) |
||
| 85 | |||
| 86 | group.user_ids = [1] |
||
| 87 | group.save! |
||
| 88 | assert !User.find(9).member_of?(project) |
||
| 89 | end |
||
| 90 | |||
| 91 | def test_user_roles_should_updated_when_updating_group_roles |
||
| 92 | group = Group.find(11) |
||
| 93 | user = User.find(9) |
||
| 94 | project = Project.first |
||
| 95 | group.users << user |
||
| 96 | m = Member.create!(:principal => group, :project => project, :role_ids => [1]) |
||
| 97 | assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort |
||
| 98 | |||
| 99 | m.role_ids = [1, 2] |
||
| 100 | assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort |
||
| 101 | |||
| 102 | m.role_ids = [2] |
||
| 103 | assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort |
||
| 104 | |||
| 105 | m.role_ids = [1] |
||
| 106 | assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort |
||
| 107 | end |
||
| 108 | |||
| 109 | def test_user_memberships_should_be_removed_when_removing_group_membership |
||
| 110 | assert User.find(8).member_of?(Project.find(5)) |
||
| 111 | Member.find_by_project_id_and_user_id(5, 10).destroy |
||
| 112 | assert !User.find(8).member_of?(Project.find(5)) |
||
| 113 | end |
||
| 114 | |||
| 115 | def test_user_roles_should_be_removed_when_removing_user_from_group |
||
| 116 | assert User.find(8).member_of?(Project.find(5)) |
||
| 117 | User.find(8).groups = [] |
||
| 118 | assert !User.find(8).member_of?(Project.find(5)) |
||
| 119 | end |
||
| 120 | |||
| 121 | def test_destroy_should_unassign_issues |
||
| 122 | group = Group.first |
||
| 123 | Issue.update_all(["assigned_to_id = ?", group.id], 'id = 1') |
||
| 124 | |||
| 125 | assert group.destroy |
||
| 126 | assert group.destroyed? |
||
| 127 | |||
| 128 | assert_equal nil, Issue.find(1).assigned_to_id |
||
| 129 | end |
||
| 130 | end |