Chris@441: # Redmine - project management software Chris@441: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@0: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@0: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@119: require File.expand_path('../../test_helper', __FILE__) Chris@0: Chris@0: class RoleTest < ActiveSupport::TestCase Chris@0: fixtures :roles, :workflows Chris@0: Chris@0: def test_copy_workflows Chris@0: source = Role.find(1) Chris@0: assert_equal 90, source.workflows.size Chris@0: Chris@0: target = Role.new(:name => 'Target') Chris@0: assert target.save Chris@0: target.workflows.copy(source) Chris@0: target.reload Chris@0: assert_equal 90, target.workflows.size Chris@0: end Chris@0: Chris@0: def test_add_permission Chris@0: role = Role.find(1) Chris@0: size = role.permissions.size Chris@0: role.add_permission!("apermission", "anotherpermission") Chris@0: role.reload Chris@0: assert role.permissions.include?(:anotherpermission) Chris@0: assert_equal size + 2, role.permissions.size Chris@0: end Chris@0: Chris@0: def test_remove_permission Chris@0: role = Role.find(1) Chris@0: size = role.permissions.size Chris@0: perm = role.permissions[0..1] Chris@0: role.remove_permission!(*perm) Chris@0: role.reload Chris@0: assert ! role.permissions.include?(perm[0]) Chris@0: assert_equal size - 2, role.permissions.size Chris@0: end Chris@441: Chris@441: def test_name Chris@441: I18n.locale = 'fr' Chris@441: assert_equal 'Manager', Role.find(1).name Chris@441: assert_equal 'Anonyme', Role.anonymous.name Chris@441: assert_equal 'Non membre', Role.non_member.name Chris@441: end Chris@0: Chris@0: context "#anonymous" do Chris@0: should "return the anonymous role" do Chris@0: role = Role.anonymous Chris@0: assert role.builtin? Chris@0: assert_equal Role::BUILTIN_ANONYMOUS, role.builtin Chris@0: end Chris@0: Chris@0: context "with a missing anonymous role" do Chris@0: setup do Chris@0: Role.delete_all("builtin = #{Role::BUILTIN_ANONYMOUS}") Chris@0: end Chris@0: Chris@0: should "create a new anonymous role" do Chris@0: assert_difference('Role.count') do Chris@0: Role.anonymous Chris@0: end Chris@0: end Chris@0: Chris@0: should "return the anonymous role" do Chris@0: role = Role.anonymous Chris@0: assert role.builtin? Chris@0: assert_equal Role::BUILTIN_ANONYMOUS, role.builtin Chris@0: end Chris@0: end Chris@0: end Chris@0: Chris@0: context "#non_member" do Chris@0: should "return the non-member role" do Chris@0: role = Role.non_member Chris@0: assert role.builtin? Chris@0: assert_equal Role::BUILTIN_NON_MEMBER, role.builtin Chris@0: end Chris@0: Chris@0: context "with a missing non-member role" do Chris@0: setup do Chris@0: Role.delete_all("builtin = #{Role::BUILTIN_NON_MEMBER}") Chris@0: end Chris@0: Chris@0: should "create a new non-member role" do Chris@0: assert_difference('Role.count') do Chris@0: Role.non_member Chris@0: end Chris@0: end Chris@0: Chris@0: should "return the non-member role" do Chris@0: role = Role.non_member Chris@0: assert role.builtin? Chris@0: assert_equal Role::BUILTIN_NON_MEMBER, role.builtin Chris@0: end Chris@0: end Chris@0: end Chris@0: end