annotate .svn/pristine/63/6360196bfabbf1ba6bec0417e53823e42158b575.svn-base @ 1295:622f24f53b42 redmine-2.3

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