;]
[askyou.git] / test / unit / role_test.rb
blobdf751eb496ca1e11c60ea8f3e7e04223f35009ae
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.
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.
18 require File.dirname(__FILE__) + '/../test_helper'
20 class RoleTest < ActiveSupport::TestCase
21   fixtures :roles, :workflows
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
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
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
53   context "#anonymous" do
54     should "return the anonymous role" do
55       role = Role.anonymous
56       assert role.builtin?
57       assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
58     end
60     context "with a missing anonymous role" do
61       setup do
62         Role.delete_all("builtin = #{Role::BUILTIN_ANONYMOUS}")
63       end
65       should "create a new anonymous role" do
66         assert_difference('Role.count') do
67           Role.anonymous
68         end
69       end
71       should "return the anonymous role" do
72         role = Role.anonymous
73         assert role.builtin?
74         assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
75       end
76     end
77   end
79   context "#non_member" do
80     should "return the non-member role" do
81       role = Role.non_member
82       assert role.builtin?
83       assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
84     end
86     context "with a missing non-member role" do
87       setup do
88         Role.delete_all("builtin = #{Role::BUILTIN_NON_MEMBER}")
89       end
91       should "create a new non-member role" do
92         assert_difference('Role.count') do
93           Role.non_member
94         end
95       end
97       should "return the non-member role" do
98         role = Role.non_member
99         assert role.builtin?
100         assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
101       end
102     end
103   end