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