annotate .svn/pristine/ae/ae670d8528dae7894b350a3933e33244d75d0910.svn-base @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19
Chris@909 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@909 32
Chris@909 33 def test_create
Chris@909 34 g = Group.new(:lastname => 'New group')
Chris@909 35 assert g.save
Chris@909 36 end
Chris@909 37
Chris@909 38 def test_blank_name_error_message
Chris@909 39 set_language_if_valid 'en'
Chris@909 40 g = Group.new
Chris@909 41 assert !g.save
Chris@909 42 assert_include "Name can't be blank", g.errors.full_messages
Chris@909 43 end
Chris@909 44
Chris@909 45 def test_blank_name_error_message_fr
Chris@909 46 set_language_if_valid 'fr'
Chris@909 47 str = "Nom doit \xc3\xaatre renseign\xc3\xa9(e)"
Chris@909 48 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
Chris@909 49 g = Group.new
Chris@909 50 assert !g.save
Chris@909 51 assert_include str, g.errors.full_messages
Chris@909 52 end
Chris@909 53
Chris@909 54 def test_roles_given_to_new_user
Chris@909 55 group = Group.find(11)
Chris@909 56 user = User.find(9)
Chris@909 57 project = Project.first
Chris@909 58
Chris@909 59 Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
Chris@909 60 group.users << user
Chris@909 61 assert user.member_of?(project)
Chris@909 62 end
Chris@909 63
Chris@909 64 def test_roles_given_to_existing_user
Chris@909 65 group = Group.find(11)
Chris@909 66 user = User.find(9)
Chris@909 67 project = Project.first
Chris@909 68
Chris@909 69 group.users << user
Chris@909 70 m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
Chris@909 71 assert user.member_of?(project)
Chris@909 72 end
Chris@909 73
Chris@909 74 def test_roles_updated
Chris@909 75 group = Group.find(11)
Chris@909 76 user = User.find(9)
Chris@909 77 project = Project.first
Chris@909 78 group.users << user
Chris@909 79 m = Member.create!(:principal => group, :project => project, :role_ids => [1])
Chris@909 80 assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort
Chris@909 81
Chris@909 82 m.role_ids = [1, 2]
Chris@909 83 assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort
Chris@909 84
Chris@909 85 m.role_ids = [2]
Chris@909 86 assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort
Chris@909 87
Chris@909 88 m.role_ids = [1]
Chris@909 89 assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort
Chris@909 90 end
Chris@909 91
Chris@909 92 def test_roles_removed_when_removing_group_membership
Chris@909 93 assert User.find(8).member_of?(Project.find(5))
Chris@909 94 Member.find_by_project_id_and_user_id(5, 10).destroy
Chris@909 95 assert !User.find(8).member_of?(Project.find(5))
Chris@909 96 end
Chris@909 97
Chris@909 98 def test_roles_removed_when_removing_user_from_group
Chris@909 99 assert User.find(8).member_of?(Project.find(5))
Chris@909 100 User.find(8).groups.clear
Chris@909 101 assert !User.find(8).member_of?(Project.find(5))
Chris@909 102 end
Chris@909 103
Chris@909 104 def test_destroy_should_unassign_issues
Chris@909 105 group = Group.first
Chris@909 106 Issue.update_all(["assigned_to_id = ?", group.id], 'id = 1')
Chris@909 107
Chris@909 108 assert group.destroy
Chris@909 109 assert group.destroyed?
Chris@909 110
Chris@909 111 assert_equal nil, Issue.find(1).assigned_to_id
Chris@909 112 end
Chris@909 113 end