Skip to content

Instantly share code, notes, and snippets.

@realmyst
Created February 12, 2012 15:48
Show Gist options
  • Save realmyst/1809125 to your computer and use it in GitHub Desktop.
Save realmyst/1809125 to your computer and use it in GitHub Desktop.
acl test example
it 'should be work with asserts' do
acl = YaAcl::Builder.build do
roles do
role :admin
role :another_user
role :editor
role :operator
end
asserts do
assert :first, [:var] do
var
end
assert :another, [:first] do
statuses = [1, 2]
statuses.include? first
end
assert :another2, [:first] do
!!first
end
assert :another3, [:first] do
statuses = [1, 2]
statuses.include? first
end
assert :another4, [:first, :second] do
first == second
end
end
resources :admin do
resource :name, [:editor, :operator] do
privilege :create do
assert :first, [:admin, :another_user]
end
privilege :update do
assert :another, [:editor]
assert :another2, [:editor, :operator]
assert :another3, [:operator]
assert :another4, [:operator]
end
end
end
end
acl.allow?(:name, :update, [:another_user]).should be_false
acl.allow?(:name, :update, [:editor], :first => true, :second => false).should be_false
acl.allow?(:name, :update, [:editor], :first => false, :second => true).should be_false
acl.allow?(:name, :update, [:editor], :first => 1, :second => true).should be_true
acl.check!(:name, :create, [:admin], :var => 2).should be_true
acl.allow?(:name, :update, [:editor], :first => 3, :second => false).should be_false
acl.allow?(:name, :update, [:operator], :first => true, :second => true).should be_false
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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment