annotate .svn/pristine/5b/5b67cbc43876349cb50763840008cc0544dfb9b5.svn-base @ 1464:261b3d9a4903 redmine-2.4

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