1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
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.
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.
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.
18 require File.dirname(__FILE__) + '/../test_helper'
20 class RoleTest < ActiveSupport::TestCase
21 fixtures :roles, :workflows
23 def test_copy_workflows
25 assert_equal 90, source.workflows.size
27 target = Role.new(:name => 'Target')
29 target.workflows.copy(source)
31 assert_equal 90, target.workflows.size
34 def test_add_permission
36 size = role.permissions.size
37 role.add_permission!("apermission", "anotherpermission")
39 assert role.permissions.include?(:anotherpermission)
40 assert_equal size + 2, role.permissions.size
43 def test_remove_permission
45 size = role.permissions.size
46 perm = role.permissions[0..1]
47 role.remove_permission!(*perm)
49 assert ! role.permissions.include?(perm[0])
50 assert_equal size - 2, role.permissions.size
53 context "#anonymous" do
54 should "return the anonymous role" do
57 assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
60 context "with a missing anonymous role" do
62 Role.delete_all("builtin = #{Role::BUILTIN_ANONYMOUS}")
65 should "create a new anonymous role" do
66 assert_difference('Role.count') do
71 should "return the anonymous role" do
74 assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
79 context "#non_member" do
80 should "return the non-member role" do
81 role = Role.non_member
83 assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
86 context "with a missing non-member role" do
88 Role.delete_all("builtin = #{Role::BUILTIN_NON_MEMBER}")
91 should "create a new non-member role" do
92 assert_difference('Role.count') do
97 should "return the non-member role" do
98 role = Role.non_member
100 assert_equal Role::BUILTIN_NON_MEMBER, role.builtin