annotate test/unit/group_test.rb @ 1480:75fd8eace091 issue_556

Close obsolete branch issue_556
author Chris Cannam
date Sat, 13 Jul 2013 15:26:30 +0100
parents 433d4f72a19b
children 622f24f53b42
rev   line source
Chris@0 1 # Redmine - project management software
Chris@1115 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19
Chris@0 20 class GroupTest < ActiveSupport::TestCase
Chris@909 21 fixtures :projects, :trackers, :issue_statuses, :issues,
Chris@909 22 :enumerations, :users, :issue_categories,
Chris@909 23 :projects_trackers,
Chris@909 24 :roles,
Chris@909 25 :member_roles,
Chris@909 26 :members,
Chris@909 27 :enabled_modules,
Chris@909 28 :workflows,
Chris@909 29 :groups_users
Chris@909 30
Chris@909 31 include Redmine::I18n
Chris@0 32
Chris@0 33 def test_create
Chris@1115 34 g = Group.new(:name => 'New group')
Chris@0 35 assert g.save
Chris@1115 36 g.reload
Chris@1115 37 assert_equal 'New group', g.name
Chris@0 38 end
Chris@909 39
Chris@909 40 def test_blank_name_error_message
Chris@909 41 set_language_if_valid 'en'
Chris@909 42 g = Group.new
Chris@909 43 assert !g.save
Chris@909 44 assert_include "Name can't be blank", g.errors.full_messages
Chris@909 45 end
Chris@909 46
Chris@909 47 def test_blank_name_error_message_fr
Chris@909 48 set_language_if_valid 'fr'
Chris@909 49 str = "Nom doit \xc3\xaatre renseign\xc3\xa9(e)"
Chris@909 50 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
Chris@909 51 g = Group.new
Chris@909 52 assert !g.save
Chris@909 53 assert_include str, g.errors.full_messages
Chris@909 54 end
Chris@909 55
Chris@1115 56 def test_group_roles_should_be_given_to_added_user
Chris@0 57 group = Group.find(11)
Chris@0 58 user = User.find(9)
Chris@0 59 project = Project.first
Chris@909 60
Chris@0 61 Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
Chris@0 62 group.users << user
Chris@0 63 assert user.member_of?(project)
Chris@0 64 end
Chris@909 65
Chris@1115 66 def test_new_roles_should_be_given_to_existing_user
Chris@0 67 group = Group.find(11)
Chris@0 68 user = User.find(9)
Chris@0 69 project = Project.first
Chris@909 70
Chris@0 71 group.users << user
Chris@0 72 m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
Chris@0 73 assert user.member_of?(project)
Chris@0 74 end
Chris@909 75
Chris@1115 76 def test_user_roles_should_updated_when_updating_user_ids
Chris@1115 77 group = Group.find(11)
Chris@1115 78 user = User.find(9)
Chris@1115 79 project = Project.first
Chris@1115 80
Chris@1115 81 Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
Chris@1115 82 group.user_ids = [user.id]
Chris@1115 83 group.save!
Chris@1115 84 assert User.find(9).member_of?(project)
Chris@1115 85
Chris@1115 86 group.user_ids = [1]
Chris@1115 87 group.save!
Chris@1115 88 assert !User.find(9).member_of?(project)
Chris@1115 89 end
Chris@1115 90
Chris@1115 91 def test_user_roles_should_updated_when_updating_group_roles
Chris@0 92 group = Group.find(11)
Chris@0 93 user = User.find(9)
Chris@0 94 project = Project.first
Chris@0 95 group.users << user
Chris@0 96 m = Member.create!(:principal => group, :project => project, :role_ids => [1])
Chris@0 97 assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort
Chris@909 98
Chris@0 99 m.role_ids = [1, 2]
Chris@0 100 assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort
Chris@909 101
Chris@0 102 m.role_ids = [2]
Chris@0 103 assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort
Chris@909 104
Chris@0 105 m.role_ids = [1]
Chris@0 106 assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort
Chris@0 107 end
Chris@0 108
Chris@1115 109 def test_user_memberships_should_be_removed_when_removing_group_membership
Chris@0 110 assert User.find(8).member_of?(Project.find(5))
Chris@0 111 Member.find_by_project_id_and_user_id(5, 10).destroy
Chris@0 112 assert !User.find(8).member_of?(Project.find(5))
Chris@0 113 end
Chris@0 114
Chris@1115 115 def test_user_roles_should_be_removed_when_removing_user_from_group
Chris@0 116 assert User.find(8).member_of?(Project.find(5))
Chris@1115 117 User.find(8).groups = []
Chris@0 118 assert !User.find(8).member_of?(Project.find(5))
Chris@0 119 end
Chris@909 120
Chris@909 121 def test_destroy_should_unassign_issues
Chris@909 122 group = Group.first
Chris@909 123 Issue.update_all(["assigned_to_id = ?", group.id], 'id = 1')
Chris@909 124
Chris@909 125 assert group.destroy
Chris@909 126 assert group.destroyed?
Chris@909 127
Chris@909 128 assert_equal nil, Issue.find(1).assigned_to_id
Chris@909 129 end
Chris@0 130 end