To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 4e / 4e6c628c00f1ea0177c61db44ecdad4a9212f134.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (4.04 KB)
| 1 | 1296:038ba2d95de8 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2012 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.expand_path('../../test_helper', __FILE__)
|
||
| 19 | |||
| 20 | class RoleTest < ActiveSupport::TestCase |
||
| 21 | fixtures :roles, :workflows, :trackers |
||
| 22 | |||
| 23 | def test_sorted_scope |
||
| 24 | assert_equal Role.all.sort, Role.sorted.all |
||
| 25 | end |
||
| 26 | |||
| 27 | def test_givable_scope |
||
| 28 | assert_equal Role.all.reject(&:builtin?).sort, Role.givable.all |
||
| 29 | end |
||
| 30 | |||
| 31 | def test_builtin_scope |
||
| 32 | assert_equal Role.all.select(&:builtin?).sort, Role.builtin(true).all.sort |
||
| 33 | assert_equal Role.all.reject(&:builtin?).sort, Role.builtin(false).all.sort |
||
| 34 | end |
||
| 35 | |||
| 36 | def test_copy_from |
||
| 37 | role = Role.find(1) |
||
| 38 | copy = Role.new.copy_from(role) |
||
| 39 | |||
| 40 | assert_nil copy.id |
||
| 41 | assert_equal '', copy.name |
||
| 42 | assert_equal role.permissions, copy.permissions |
||
| 43 | |||
| 44 | copy.name = 'Copy' |
||
| 45 | assert copy.save |
||
| 46 | end |
||
| 47 | |||
| 48 | def test_copy_workflows |
||
| 49 | source = Role.find(1) |
||
| 50 | assert_equal 90, source.workflow_rules.size |
||
| 51 | |||
| 52 | target = Role.new(:name => 'Target') |
||
| 53 | assert target.save |
||
| 54 | target.workflow_rules.copy(source) |
||
| 55 | target.reload |
||
| 56 | assert_equal 90, target.workflow_rules.size |
||
| 57 | end |
||
| 58 | |||
| 59 | def test_permissions_should_be_unserialized_with_its_coder |
||
| 60 | Role::PermissionsAttributeCoder.expects(:load).once |
||
| 61 | Role.find(1).permissions |
||
| 62 | end |
||
| 63 | |||
| 64 | def test_add_permission |
||
| 65 | role = Role.find(1) |
||
| 66 | size = role.permissions.size |
||
| 67 | role.add_permission!("apermission", "anotherpermission")
|
||
| 68 | role.reload |
||
| 69 | assert role.permissions.include?(:anotherpermission) |
||
| 70 | assert_equal size + 2, role.permissions.size |
||
| 71 | end |
||
| 72 | |||
| 73 | def test_remove_permission |
||
| 74 | role = Role.find(1) |
||
| 75 | size = role.permissions.size |
||
| 76 | perm = role.permissions[0..1] |
||
| 77 | role.remove_permission!(*perm) |
||
| 78 | role.reload |
||
| 79 | assert ! role.permissions.include?(perm[0]) |
||
| 80 | assert_equal size - 2, role.permissions.size |
||
| 81 | end |
||
| 82 | |||
| 83 | def test_name |
||
| 84 | I18n.locale = 'fr' |
||
| 85 | assert_equal 'Manager', Role.find(1).name |
||
| 86 | assert_equal 'Anonyme', Role.anonymous.name |
||
| 87 | assert_equal 'Non membre', Role.non_member.name |
||
| 88 | end |
||
| 89 | |||
| 90 | def test_find_all_givable |
||
| 91 | assert_equal Role.all.reject(&:builtin?).sort, Role.find_all_givable |
||
| 92 | end |
||
| 93 | |||
| 94 | context "#anonymous" do |
||
| 95 | should "return the anonymous role" do |
||
| 96 | role = Role.anonymous |
||
| 97 | assert role.builtin? |
||
| 98 | assert_equal Role::BUILTIN_ANONYMOUS, role.builtin |
||
| 99 | end |
||
| 100 | |||
| 101 | context "with a missing anonymous role" do |
||
| 102 | setup do |
||
| 103 | Role.delete_all("builtin = #{Role::BUILTIN_ANONYMOUS}")
|
||
| 104 | end |
||
| 105 | |||
| 106 | should "create a new anonymous role" do |
||
| 107 | assert_difference('Role.count') do
|
||
| 108 | Role.anonymous |
||
| 109 | end |
||
| 110 | end |
||
| 111 | |||
| 112 | should "return the anonymous role" do |
||
| 113 | role = Role.anonymous |
||
| 114 | assert role.builtin? |
||
| 115 | assert_equal Role::BUILTIN_ANONYMOUS, role.builtin |
||
| 116 | end |
||
| 117 | end |
||
| 118 | end |
||
| 119 | |||
| 120 | context "#non_member" do |
||
| 121 | should "return the non-member role" do |
||
| 122 | role = Role.non_member |
||
| 123 | assert role.builtin? |
||
| 124 | assert_equal Role::BUILTIN_NON_MEMBER, role.builtin |
||
| 125 | end |
||
| 126 | |||
| 127 | context "with a missing non-member role" do |
||
| 128 | setup do |
||
| 129 | Role.delete_all("builtin = #{Role::BUILTIN_NON_MEMBER}")
|
||
| 130 | end |
||
| 131 | |||
| 132 | should "create a new non-member role" do |
||
| 133 | assert_difference('Role.count') do
|
||
| 134 | Role.non_member |
||
| 135 | end |
||
| 136 | end |
||
| 137 | |||
| 138 | should "return the non-member role" do |
||
| 139 | role = Role.non_member |
||
| 140 | assert role.builtin? |
||
| 141 | assert_equal Role::BUILTIN_NON_MEMBER, role.builtin |
||
| 142 | end |
||
| 143 | end |
||
| 144 | end |
||
| 145 | end |