annotate .svn/pristine/a3/a3a58ab9f9fc5bc4302fa7dbcd592c4ba267cc9b.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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