annotate .svn/pristine/8a/8ab3fca595d796b8067a92013b3447a2478c5b88.svn-base @ 1517:dffacf8a6908 redmine-2.5

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