annotate test/unit/group_test.rb @ 854:be557d78a11b bug_94

Close obsolete branch bug_94
author Chris Cannam
date Thu, 14 Jul 2011 12:45:24 +0100
parents 513646585e45
children af80e5618e9b
rev   line source
Chris@0 1 # Redmine - project management software
Chris@0 2 # Copyright (C) 2006-2009 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@0 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@0 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@0 18 require File.dirname(__FILE__) + '/../test_helper'
Chris@0 19
Chris@0 20 class GroupTest < ActiveSupport::TestCase
Chris@0 21 fixtures :all
Chris@0 22
Chris@0 23 def test_create
Chris@0 24 g = Group.new(:lastname => 'New group')
Chris@0 25 assert g.save
Chris@0 26 end
Chris@0 27
Chris@0 28 def test_roles_given_to_new_user
Chris@0 29 group = Group.find(11)
Chris@0 30 user = User.find(9)
Chris@0 31 project = Project.first
Chris@0 32
Chris@0 33 Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
Chris@0 34 group.users << user
Chris@0 35 assert user.member_of?(project)
Chris@0 36 end
Chris@0 37
Chris@0 38 def test_roles_given_to_existing_user
Chris@0 39 group = Group.find(11)
Chris@0 40 user = User.find(9)
Chris@0 41 project = Project.first
Chris@0 42
Chris@0 43 group.users << user
Chris@0 44 m = Member.create!(:principal => group, :project => project, :role_ids => [1, 2])
Chris@0 45 assert user.member_of?(project)
Chris@0 46 end
Chris@0 47
Chris@0 48 def test_roles_updated
Chris@0 49 group = Group.find(11)
Chris@0 50 user = User.find(9)
Chris@0 51 project = Project.first
Chris@0 52 group.users << user
Chris@0 53 m = Member.create!(:principal => group, :project => project, :role_ids => [1])
Chris@0 54 assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort
Chris@0 55
Chris@0 56 m.role_ids = [1, 2]
Chris@0 57 assert_equal [1, 2], user.reload.roles_for_project(project).collect(&:id).sort
Chris@0 58
Chris@0 59 m.role_ids = [2]
Chris@0 60 assert_equal [2], user.reload.roles_for_project(project).collect(&:id).sort
Chris@0 61
Chris@0 62 m.role_ids = [1]
Chris@0 63 assert_equal [1], user.reload.roles_for_project(project).collect(&:id).sort
Chris@0 64 end
Chris@0 65
Chris@0 66 def test_roles_removed_when_removing_group_membership
Chris@0 67 assert User.find(8).member_of?(Project.find(5))
Chris@0 68 Member.find_by_project_id_and_user_id(5, 10).destroy
Chris@0 69 assert !User.find(8).member_of?(Project.find(5))
Chris@0 70 end
Chris@0 71
Chris@0 72 def test_roles_removed_when_removing_user_from_group
Chris@0 73 assert User.find(8).member_of?(Project.find(5))
Chris@0 74 User.find(8).groups.clear
Chris@0 75 assert !User.find(8).member_of?(Project.find(5))
Chris@0 76 end
Chris@0 77 end