annotate .svn/pristine/4e/4e6c628c00f1ea0177c61db44ecdad4a9212f134.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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