diff --git a/lib/ya_acl/builder.rb b/lib/ya_acl/builder.rb index e338424..eec094d 100644 --- a/lib/ya_acl/builder.rb +++ b/lib/ya_acl/builder.rb @@ -35,7 +35,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) diff --git a/spec/ya_acl/builder_spec.rb b/spec/ya_acl/builder_spec.rb index 1a6ebef..9df4663 100644 --- a/spec/ya_acl/builder_spec.rb +++ b/spec/ya_acl/builder_spec.rb @@ -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