annotate .svn/pristine/59/590eaa24ab9f834ac16f2b590030d2f8381b4376.svn-base @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19
Chris@909 20 class RoleTest < ActiveSupport::TestCase
Chris@909 21 fixtures :roles, :workflows
Chris@909 22
Chris@909 23 def test_copy_workflows
Chris@909 24 source = Role.find(1)
Chris@909 25 assert_equal 90, source.workflows.size
Chris@909 26
Chris@909 27 target = Role.new(:name => 'Target')
Chris@909 28 assert target.save
Chris@909 29 target.workflows.copy(source)
Chris@909 30 target.reload
Chris@909 31 assert_equal 90, target.workflows.size
Chris@909 32 end
Chris@909 33
Chris@909 34 def test_add_permission
Chris@909 35 role = Role.find(1)
Chris@909 36 size = role.permissions.size
Chris@909 37 role.add_permission!("apermission", "anotherpermission")
Chris@909 38 role.reload
Chris@909 39 assert role.permissions.include?(:anotherpermission)
Chris@909 40 assert_equal size + 2, role.permissions.size
Chris@909 41 end
Chris@909 42
Chris@909 43 def test_remove_permission
Chris@909 44 role = Role.find(1)
Chris@909 45 size = role.permissions.size
Chris@909 46 perm = role.permissions[0..1]
Chris@909 47 role.remove_permission!(*perm)
Chris@909 48 role.reload
Chris@909 49 assert ! role.permissions.include?(perm[0])
Chris@909 50 assert_equal size - 2, role.permissions.size
Chris@909 51 end
Chris@909 52
Chris@909 53 def test_name
Chris@909 54 I18n.locale = 'fr'
Chris@909 55 assert_equal 'Manager', Role.find(1).name
Chris@909 56 assert_equal 'Anonyme', Role.anonymous.name
Chris@909 57 assert_equal 'Non membre', Role.non_member.name
Chris@909 58 end
Chris@909 59
Chris@909 60 context "#anonymous" do
Chris@909 61 should "return the anonymous role" do
Chris@909 62 role = Role.anonymous
Chris@909 63 assert role.builtin?
Chris@909 64 assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
Chris@909 65 end
Chris@909 66
Chris@909 67 context "with a missing anonymous role" do
Chris@909 68 setup do
Chris@909 69 Role.delete_all("builtin = #{Role::BUILTIN_ANONYMOUS}")
Chris@909 70 end
Chris@909 71
Chris@909 72 should "create a new anonymous role" do
Chris@909 73 assert_difference('Role.count') do
Chris@909 74 Role.anonymous
Chris@909 75 end
Chris@909 76 end
Chris@909 77
Chris@909 78 should "return the anonymous role" do
Chris@909 79 role = Role.anonymous
Chris@909 80 assert role.builtin?
Chris@909 81 assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
Chris@909 82 end
Chris@909 83 end
Chris@909 84 end
Chris@909 85
Chris@909 86 context "#non_member" do
Chris@909 87 should "return the non-member role" do
Chris@909 88 role = Role.non_member
Chris@909 89 assert role.builtin?
Chris@909 90 assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
Chris@909 91 end
Chris@909 92
Chris@909 93 context "with a missing non-member role" do
Chris@909 94 setup do
Chris@909 95 Role.delete_all("builtin = #{Role::BUILTIN_NON_MEMBER}")
Chris@909 96 end
Chris@909 97
Chris@909 98 should "create a new non-member role" do
Chris@909 99 assert_difference('Role.count') do
Chris@909 100 Role.non_member
Chris@909 101 end
Chris@909 102 end
Chris@909 103
Chris@909 104 should "return the non-member role" do
Chris@909 105 role = Role.non_member
Chris@909 106 assert role.builtin?
Chris@909 107 assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
Chris@909 108 end
Chris@909 109 end
Chris@909 110 end
Chris@909 111 end