Commit 76ed18942b5f0c43af17a678ea7d18de1a599f6e
Committed by
Antonio Terceiro
1 parent
ae454ce9
Exists in
master
and in
23 other branches
ActionItem1204: made role kind always be defined
Showing
2 changed files
with
14 additions
and
1 deletions
Show diff stats
test/functional/role_controller_test.rb
| @@ -82,4 +82,12 @@ class RoleControllerTest < Test::Unit::TestCase | @@ -82,4 +82,12 @@ class RoleControllerTest < Test::Unit::TestCase | ||
| 82 | assert_not_nil assigns(:role) | 82 | assert_not_nil assigns(:role) |
| 83 | end | 83 | end |
| 84 | end | 84 | end |
| 85 | + | ||
| 86 | + should 'not crash when editing role with no permissions' do | ||
| 87 | + role = Role.create!(:name => 'test_role', :environment => Environment.default) | ||
| 88 | + | ||
| 89 | + assert_nothing_raised do | ||
| 90 | + get :edit, :id => role.id | ||
| 91 | + end | ||
| 92 | + end | ||
| 85 | end | 93 | end |
vendor/plugins/access_control/lib/role.rb
| @@ -32,7 +32,12 @@ class Role < ActiveRecord::Base | @@ -32,7 +32,12 @@ class Role < ActiveRecord::Base | ||
| 32 | end | 32 | end |
| 33 | 33 | ||
| 34 | def kind | 34 | def kind |
| 35 | - perms.keys.detect{|k| perms[k].keys.include?(permissions[0]) } | 35 | + env_perms = perms['Environment'].keys |
| 36 | + if permissions.any?{ |perm| env_perms.include?(perm) } | ||
| 37 | + 'Environment' | ||
| 38 | + else | ||
| 39 | + 'Profile' | ||
| 40 | + end | ||
| 36 | end | 41 | end |
| 37 | 42 | ||
| 38 | def name | 43 | def name |