annotate .svn/pristine/ac/ac3d46576ac0d49645b8babc84dcdd0e6f305a12.svn-base @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1295 19
Chris@1295 20 class RoleTest < ActiveSupport::TestCase
Chris@1295 21 fixtures :roles, :workflows, :trackers
Chris@1295 22
Chris@1295 23 def test_sorted_scope
Chris@1295 24 assert_equal Role.all.sort, Role.sorted.all
Chris@1295 25 end
Chris@1295 26
Chris@1295 27 def test_givable_scope
Chris@1295 28 assert_equal Role.all.reject(&:builtin?).sort, Role.givable.all
Chris@1295 29 end
Chris@1295 30
Chris@1295 31 def test_builtin_scope
Chris@1295 32 assert_equal Role.all.select(&:builtin?).sort, Role.builtin(true).all.sort
Chris@1295 33 assert_equal Role.all.reject(&:builtin?).sort, Role.builtin(false).all.sort
Chris@1295 34 end
Chris@1295 35
Chris@1295 36 def test_copy_from
Chris@1295 37 role = Role.find(1)
Chris@1295 38 copy = Role.new.copy_from(role)
Chris@1295 39
Chris@1295 40 assert_nil copy.id
Chris@1295 41 assert_equal '', copy.name
Chris@1295 42 assert_equal role.permissions, copy.permissions
Chris@1295 43
Chris@1295 44 copy.name = 'Copy'
Chris@1295 45 assert copy.save
Chris@1295 46 end
Chris@1295 47
Chris@1295 48 def test_copy_workflows
Chris@1295 49 source = Role.find(1)
Chris@1295 50 assert_equal 90, source.workflow_rules.size
Chris@1295 51
Chris@1295 52 target = Role.new(:name => 'Target')
Chris@1295 53 assert target.save
Chris@1295 54 target.workflow_rules.copy(source)
Chris@1295 55 target.reload
Chris@1295 56 assert_equal 90, target.workflow_rules.size
Chris@1295 57 end
Chris@1295 58
Chris@1295 59 def test_permissions_should_be_unserialized_with_its_coder
Chris@1295 60 Role::PermissionsAttributeCoder.expects(:load).once
Chris@1295 61 Role.find(1).permissions
Chris@1295 62 end
Chris@1295 63
Chris@1295 64 def test_add_permission
Chris@1295 65 role = Role.find(1)
Chris@1295 66 size = role.permissions.size
Chris@1295 67 role.add_permission!("apermission", "anotherpermission")
Chris@1295 68 role.reload
Chris@1295 69 assert role.permissions.include?(:anotherpermission)
Chris@1295 70 assert_equal size + 2, role.permissions.size
Chris@1295 71 end
Chris@1295 72
Chris@1295 73 def test_remove_permission
Chris@1295 74 role = Role.find(1)
Chris@1295 75 size = role.permissions.size
Chris@1295 76 perm = role.permissions[0..1]
Chris@1295 77 role.remove_permission!(*perm)
Chris@1295 78 role.reload
Chris@1295 79 assert ! role.permissions.include?(perm[0])
Chris@1295 80 assert_equal size - 2, role.permissions.size
Chris@1295 81 end
Chris@1295 82
Chris@1295 83 def test_name
Chris@1295 84 I18n.locale = 'fr'
Chris@1295 85 assert_equal 'Manager', Role.find(1).name
Chris@1295 86 assert_equal 'Anonyme', Role.anonymous.name
Chris@1295 87 assert_equal 'Non membre', Role.non_member.name
Chris@1295 88 end
Chris@1295 89
Chris@1295 90 def test_find_all_givable
Chris@1295 91 assert_equal Role.all.reject(&:builtin?).sort, Role.find_all_givable
Chris@1295 92 end
Chris@1295 93
Chris@1295 94 context "#anonymous" do
Chris@1295 95 should "return the anonymous role" do
Chris@1295 96 role = Role.anonymous
Chris@1295 97 assert role.builtin?
Chris@1295 98 assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
Chris@1295 99 end
Chris@1295 100
Chris@1295 101 context "with a missing anonymous role" do
Chris@1295 102 setup do
Chris@1295 103 Role.delete_all("builtin = #{Role::BUILTIN_ANONYMOUS}")
Chris@1295 104 end
Chris@1295 105
Chris@1295 106 should "create a new anonymous role" do
Chris@1295 107 assert_difference('Role.count') do
Chris@1295 108 Role.anonymous
Chris@1295 109 end
Chris@1295 110 end
Chris@1295 111
Chris@1295 112 should "return the anonymous role" do
Chris@1295 113 role = Role.anonymous
Chris@1295 114 assert role.builtin?
Chris@1295 115 assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
Chris@1295 116 end
Chris@1295 117 end
Chris@1295 118 end
Chris@1295 119
Chris@1295 120 context "#non_member" do
Chris@1295 121 should "return the non-member role" do
Chris@1295 122 role = Role.non_member
Chris@1295 123 assert role.builtin?
Chris@1295 124 assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
Chris@1295 125 end
Chris@1295 126
Chris@1295 127 context "with a missing non-member role" do
Chris@1295 128 setup do
Chris@1295 129 Role.delete_all("builtin = #{Role::BUILTIN_NON_MEMBER}")
Chris@1295 130 end
Chris@1295 131
Chris@1295 132 should "create a new non-member role" do
Chris@1295 133 assert_difference('Role.count') do
Chris@1295 134 Role.non_member
Chris@1295 135 end
Chris@1295 136 end
Chris@1295 137
Chris@1295 138 should "return the non-member role" do
Chris@1295 139 role = Role.non_member
Chris@1295 140 assert role.builtin?
Chris@1295 141 assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
Chris@1295 142 end
Chris@1295 143 end
Chris@1295 144 end
Chris@1295 145 end