From 76ed18942b5f0c43af17a678ea7d18de1a599f6e Mon Sep 17 00:00:00 2001 From: Moises Machado Date: Thu, 17 Sep 2009 18:36:41 -0300 Subject: [PATCH] ActionItem1204: made role kind always be defined --- test/functional/role_controller_test.rb | 8 ++++++++ vendor/plugins/access_control/lib/role.rb | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/test/functional/role_controller_test.rb b/test/functional/role_controller_test.rb index 3c37e4a..4dbce9c 100644 --- a/test/functional/role_controller_test.rb +++ b/test/functional/role_controller_test.rb @@ -82,4 +82,12 @@ class RoleControllerTest < Test::Unit::TestCase assert_not_nil assigns(:role) end end + + should 'not crash when editing role with no permissions' do + role = Role.create!(:name => 'test_role', :environment => Environment.default) + + assert_nothing_raised do + get :edit, :id => role.id + end + end end diff --git a/vendor/plugins/access_control/lib/role.rb b/vendor/plugins/access_control/lib/role.rb index bc410d0..241b835 100644 --- a/vendor/plugins/access_control/lib/role.rb +++ b/vendor/plugins/access_control/lib/role.rb @@ -32,7 +32,12 @@ class Role < ActiveRecord::Base end def kind - perms.keys.detect{|k| perms[k].keys.include?(permissions[0]) } + env_perms = perms['Environment'].keys + if permissions.any?{ |perm| env_perms.include?(perm) } + 'Environment' + else + 'Profile' + end end def name -- libgit2 0.21.2