annotate test/unit/role_test.rb @ 1176:7d9db6065048 bug_352

Close obsolete branch bug_352
author Chris Cannam
date Wed, 01 Feb 2012 16:09:00 +0000
parents cbce1fd3b1b7
children cbb26bc654de
rev   line source
Chris@441 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 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@0 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@0 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@0 21 fixtures :roles, :workflows
Chris@0 22
Chris@0 23 def test_copy_workflows
Chris@0 24 source = Role.find(1)
Chris@0 25 assert_equal 90, source.workflows.size
Chris@0 26
Chris@0 27 target = Role.new(:name => 'Target')
Chris@0 28 assert target.save
Chris@0 29 target.workflows.copy(source)
Chris@0 30 target.reload
Chris@0 31 assert_equal 90, target.workflows.size
Chris@0 32 end
Chris@0 33
Chris@0 34 def test_add_permission
Chris@0 35 role = Role.find(1)
Chris@0 36 size = role.permissions.size
Chris@0 37 role.add_permission!("apermission", "anotherpermission")
Chris@0 38 role.reload
Chris@0 39 assert role.permissions.include?(:anotherpermission)
Chris@0 40 assert_equal size + 2, role.permissions.size
Chris@0 41 end
Chris@0 42
Chris@0 43 def test_remove_permission
Chris@0 44 role = Role.find(1)
Chris@0 45 size = role.permissions.size
Chris@0 46 perm = role.permissions[0..1]
Chris@0 47 role.remove_permission!(*perm)
Chris@0 48 role.reload
Chris@0 49 assert ! role.permissions.include?(perm[0])
Chris@0 50 assert_equal size - 2, role.permissions.size
Chris@0 51 end
Chris@441 52
Chris@441 53 def test_name
Chris@441 54 I18n.locale = 'fr'
Chris@441 55 assert_equal 'Manager', Role.find(1).name
Chris@441 56 assert_equal 'Anonyme', Role.anonymous.name
Chris@441 57 assert_equal 'Non membre', Role.non_member.name
Chris@441 58 end
Chris@0 59
Chris@0 60 context "#anonymous" do
Chris@0 61 should "return the anonymous role" do
Chris@0 62 role = Role.anonymous
Chris@0 63 assert role.builtin?
Chris@0 64 assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
Chris@0 65 end
Chris@0 66
Chris@0 67 context "with a missing anonymous role" do
Chris@0 68 setup do
Chris@0 69 Role.delete_all("builtin = #{Role::BUILTIN_ANONYMOUS}")
Chris@0 70 end
Chris@0 71
Chris@0 72 should "create a new anonymous role" do
Chris@0 73 assert_difference('Role.count') do
Chris@0 74 Role.anonymous
Chris@0 75 end
Chris@0 76 end
Chris@0 77
Chris@0 78 should "return the anonymous role" do
Chris@0 79 role = Role.anonymous
Chris@0 80 assert role.builtin?
Chris@0 81 assert_equal Role::BUILTIN_ANONYMOUS, role.builtin
Chris@0 82 end
Chris@0 83 end
Chris@0 84 end
Chris@0 85
Chris@0 86 context "#non_member" do
Chris@0 87 should "return the non-member role" do
Chris@0 88 role = Role.non_member
Chris@0 89 assert role.builtin?
Chris@0 90 assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
Chris@0 91 end
Chris@0 92
Chris@0 93 context "with a missing non-member role" do
Chris@0 94 setup do
Chris@0 95 Role.delete_all("builtin = #{Role::BUILTIN_NON_MEMBER}")
Chris@0 96 end
Chris@0 97
Chris@0 98 should "create a new non-member role" do
Chris@0 99 assert_difference('Role.count') do
Chris@0 100 Role.non_member
Chris@0 101 end
Chris@0 102 end
Chris@0 103
Chris@0 104 should "return the non-member role" do
Chris@0 105 role = Role.non_member
Chris@0 106 assert role.builtin?
Chris@0 107 assert_equal Role::BUILTIN_NON_MEMBER, role.builtin
Chris@0 108 end
Chris@0 109 end
Chris@0 110 end
Chris@0 111 end