annotate test/unit/role_test.rb @ 1298:4f746d8966dd redmine_2.3_integration

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