OSDN Git Service

1e76dd887fa8e8440fce4990d6fe55a1757ce67c
[redminele/redminele.git] / redmine / test / unit / role_test.rb
1 # redMine - project management software
2 # Copyright (C) 2006-2008  Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../test_helper'
19
20 class RoleTest < ActiveSupport::TestCase
21   fixtures :roles, :workflows
22
23   def test_copy_workflows
24     source = Role.find(1)
25     assert_equal 90, source.workflows.size
26     
27     target = Role.new(:name => 'Target')
28     assert target.save
29     target.workflows.copy(source)
30     target.reload
31     assert_equal 90, target.workflows.size
32   end
33
34   def test_add_permission
35     role = Role.find(1)
36     size = role.permissions.size
37     role.add_permission!("apermission", "anotherpermission")
38     role.reload
39     assert role.permissions.include?(:anotherpermission)
40     assert_equal size + 2, role.permissions.size
41   end
42
43   def test_remove_permission
44     role = Role.find(1)
45     size = role.permissions.size
46     perm = role.permissions[0..1]
47     role.remove_permission!(*perm)
48     role.reload
49     assert ! role.permissions.include?(perm[0])
50     assert_equal size - 2, role.permissions.size
51   end
52
53 end