diff --git a/lib/ya_acl/builder.rb b/lib/ya_acl/builder.rb index d44a35f..162dc1d 100644 --- a/lib/ya_acl/builder.rb +++ b/lib/ya_acl/builder.rb @@ -36,7 +36,8 @@ def resources(allow, &block) def resource(name, allow_roles = [], &block) raise ArgumentError, 'Options "allow_roles" must be Array' unless allow_roles.is_a? Array - resource_allow_roles = allow_roles << @global_allow_role + resource_allow_roles = allow_roles + resource_allow_roles << @global_allow_role if @global_allow_role resource = Resource.new(name) acl.add_resource resource PrivilegeProxy.new(resource.name, resource_allow_roles, acl, block) @@ -58,7 +59,7 @@ def privilege(privilege_name, roles = [], &asserts_block) proxy = PrivilegeAssertProxy.new(asserts_block, all_allow_roles) asserts = proxy.asserts end - + all_allow_roles.each do |role| if asserts[role] asserts[role].each do |assert| @@ -73,7 +74,7 @@ def privilege(privilege_name, roles = [], &asserts_block) class PrivilegeAssertProxy attr_reader :asserts - + def initialize(block, all_allow_roles) @all_allow_roles = all_allow_roles @asserts = {} diff --git a/spec/ya_acl/builder_spec.rb b/spec/ya_acl/builder_spec.rb index 52c34db..6bc1861 100644 --- a/spec/ya_acl/builder_spec.rb +++ b/spec/ya_acl/builder_spec.rb @@ -7,7 +7,7 @@ role :admin, :name => 'Administrator' end end - + acl.role(:admin).should_not be_nil end @@ -42,7 +42,7 @@ end end end - + acl.check!(:name, :index, [:admin]).should be_true acl.check!(:name, :index, [:another_admin]).should be_true acl.check!(:name, :index, [:operator]).should be_true @@ -143,4 +143,18 @@ acl.allow?(:name, :update, [:operator], :first => 1, :second => 1).should be_true acl.allow?(:name, :update, [:operator], :first => 3, :second => 3).should be_false end + + it 'should be work without global role' do + acl = YaAcl::Builder.build do + roles do + role :admin + end + + resource :name, [:admin] do + privilege :index + end + end + + acl.check!(:name, :index, [:admin]).should be_true + end end \ No newline at end of file