To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / unit / .svn / text-base / role_test.rb.svn-base @ 441:cbce1fd3b1b7

History | View | Annotate | Download (3.17 KB)

1 441:cbce1fd3b1b7 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 0:513646585e45 Chris
#
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 119:8661b858af72 Chris
require File.expand_path('../../test_helper', __FILE__)
19 0:513646585e45 Chris
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 441:cbce1fd3b1b7 Chris
53
  def test_name
54
    I18n.locale = 'fr'
55
    assert_equal 'Manager', Role.find(1).name
56
    assert_equal 'Anonyme', Role.anonymous.name
57
    assert_equal 'Non membre', Role.non_member.name
58
  end
59 0:513646585e45 Chris
60
  context "#anonymous" do
61
    should "return the anonymous role" do
62
      role = Role.anonymous
63
      assert role.builtin?
64
      assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
65
    end
66
67
    context "with a missing anonymous role" do
68
      setup do
69
        Role.delete_all("builtin = #{Role::BUILTIN_ANONYMOUS}")
70
      end
71
72
      should "create a new anonymous role" do
73
        assert_difference('Role.count') do
74
          Role.anonymous
75
        end
76
      end
77
78
      should "return the anonymous role" do
79
        role = Role.anonymous
80
        assert role.builtin?
81
        assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
82
      end
83
    end
84
  end
85
86
  context "#non_member" do
87
    should "return the non-member role" do
88
      role = Role.non_member
89
      assert role.builtin?
90
      assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
91
    end
92
93
    context "with a missing non-member role" do
94
      setup do
95
        Role.delete_all("builtin = #{Role::BUILTIN_NON_MEMBER}")
96
      end
97
98
      should "create a new non-member role" do
99
        assert_difference('Role.count') do
100
          Role.non_member
101
        end
102
      end
103
104
      should "return the non-member role" do
105
        role = Role.non_member
106
        assert role.builtin?
107
        assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
108
      end
109
    end
110
  end
111
end