access_schema 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/Gemfile +15 -0
- data/Guardfile +5 -0
- data/LICENSE +21 -0
- data/README.md +102 -0
- data/Rakefile +1 -0
- data/access_schema.gemspec +24 -0
- data/lib/access_schema/assert.rb +24 -0
- data/lib/access_schema/builders/asserts_builder.rb +12 -0
- data/lib/access_schema/builders/basic_builder.rb +11 -0
- data/lib/access_schema/builders/element_builder.rb +10 -0
- data/lib/access_schema/builders/namespace_builder.rb +16 -0
- data/lib/access_schema/builders/roles_builder.rb +11 -0
- data/lib/access_schema/builders/schema_builder.rb +36 -0
- data/lib/access_schema/element.rb +24 -0
- data/lib/access_schema/exceptions.rb +9 -0
- data/lib/access_schema/expectation.rb +17 -0
- data/lib/access_schema/namespace.rb +16 -0
- data/lib/access_schema/proxy.rb +27 -0
- data/lib/access_schema/schema.rb +80 -0
- data/lib/access_schema/version.rb +3 -0
- data/lib/access_schema.rb +33 -0
- data/spec/access_schema_spec.rb +43 -0
- data/spec/assess_schema/proxy_spec.rb +0 -0
- data/spec/assess_schema/schema_builder_spec.rb +110 -0
- data/spec/assess_schema/schema_spec.rb +39 -0
- data/spec/schema_example.rb +27 -0
- data/spec/spec_helper.rb +8 -0
- metadata +81 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in hydroplan.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem "rake"
|
8
|
+
|
9
|
+
gem "rspec"
|
10
|
+
gem "rack-test"
|
11
|
+
gem "guard"
|
12
|
+
gem "guard-rspec"
|
13
|
+
gem "rb-fsevent", :require => false
|
14
|
+
end
|
15
|
+
|
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2012 Victor Gumayunov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# AccessSchema gem - ACL/plans for your app
|
2
|
+
|
3
|
+
AccessSchema provides a tool to define ACL schema with simple DSL.
|
4
|
+
Inspired by [ya_acl](https://github.com/kaize/ya_acl)
|
5
|
+
|
6
|
+
With a couple of aliases in DSL it enables you to deal with tariff plans. Plan and role, feature and privilege are synonyms.
|
7
|
+
|
8
|
+
```
|
9
|
+
gem install access_schema
|
10
|
+
```
|
11
|
+
|
12
|
+
## An example of typical use
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
#somewhere.rb
|
16
|
+
|
17
|
+
acl.require! review, :edit
|
18
|
+
|
19
|
+
plan.allow? review, :add_photo
|
20
|
+
|
21
|
+
plan.require! review, :mark_featured
|
22
|
+
|
23
|
+
```
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# config/plans.rb
|
27
|
+
plans do
|
28
|
+
plan :none
|
29
|
+
plan :bulb
|
30
|
+
plan :flower
|
31
|
+
plan :bouquet
|
32
|
+
end
|
33
|
+
|
34
|
+
asserts do
|
35
|
+
|
36
|
+
assert :photo_limit, [:limit] do
|
37
|
+
subject.photos_count < limit
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
namespace "Review" do
|
43
|
+
|
44
|
+
feature :mark_featured, [:flower, :bouquet]
|
45
|
+
|
46
|
+
feature :add_photo, [:bouquet] do
|
47
|
+
assert :photo_limit, [:none], :limit => 1
|
48
|
+
assert :photo_limit, [:bulb], :limit => 5
|
49
|
+
assert :photo_limit, [:flower], :limit => 10
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# config/acl.rb
|
57
|
+
roles do
|
58
|
+
role :none
|
59
|
+
role :admin
|
60
|
+
end
|
61
|
+
|
62
|
+
asserts do
|
63
|
+
|
64
|
+
assert :owner, [:user_id] do
|
65
|
+
subject.author.id == user_id
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
namespace "Review" do
|
71
|
+
|
72
|
+
privilege :edit, [:admin] do
|
73
|
+
assert :owner, [:none]
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
#access_schema_helper.rb
|
82
|
+
|
83
|
+
class AccessSchemaHelper
|
84
|
+
|
85
|
+
def plan
|
86
|
+
@plan ||= AccessSchema.build_file "config/plans.rb"
|
87
|
+
AccessSchema.with_options(@plan, {
|
88
|
+
:plan => Rails.development? && params[:debug_plan] || current_user.try(:plan) || :none
|
89
|
+
})
|
90
|
+
end
|
91
|
+
|
92
|
+
def acl
|
93
|
+
@acl ||= AccessSchema.build_file "config/acl.rb"
|
94
|
+
AccessSchema.with_options(@acl, {
|
95
|
+
:role => current_user.try(:role) || :none,
|
96
|
+
:user_id => current_user.try(:id)
|
97
|
+
})
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "access_schema/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "access_schema"
|
7
|
+
s.version = AccessSchema::VERSION
|
8
|
+
s.authors = ["Victor Gumayunov"]
|
9
|
+
s.email = ["gumayunov@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{AccessSchema is an ACL tool}
|
12
|
+
s.description = %q{AccessSchema is a tool for ACL or tariff plans schema definition and checks}
|
13
|
+
|
14
|
+
s.rubyforge_project = "access_schema"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AccessSchema
|
2
|
+
class Assert
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(name, vars, &block)
|
6
|
+
@name = name
|
7
|
+
@block = block
|
8
|
+
vars << :subject unless vars.include?(:subject)
|
9
|
+
(class << self; self; end).class_eval do
|
10
|
+
vars.each do |name|
|
11
|
+
define_method name do
|
12
|
+
@options[name]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def check?(options)
|
19
|
+
@options = options
|
20
|
+
self.instance_eval(&@block)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module AccessSchema
|
2
|
+
class NamespaceBuilder < BasicBuilder
|
3
|
+
|
4
|
+
def privilege(name, roles, &block)
|
5
|
+
element = Element.new(name.to_sym, roles.map(&:to_sym))
|
6
|
+
if block_given?
|
7
|
+
builder = ElementBuilder.new(element)
|
8
|
+
builder.instance_eval(&block)
|
9
|
+
end
|
10
|
+
schema.add_element(element)
|
11
|
+
end
|
12
|
+
|
13
|
+
alias :feature :privilege
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module AccessSchema
|
2
|
+
class SchemaBuilder < BasicBuilder
|
3
|
+
|
4
|
+
def self.build(&block)
|
5
|
+
builder = new(Schema.new)
|
6
|
+
builder.instance_eval(&block)
|
7
|
+
builder.schema.freeze
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.build_file(filename)
|
11
|
+
builder = new(Schema.new)
|
12
|
+
builder.instance_eval(File.read(filename))
|
13
|
+
builder.schema.freeze
|
14
|
+
end
|
15
|
+
|
16
|
+
def roles(&block)
|
17
|
+
builder = RolesBuilder.new(schema)
|
18
|
+
builder.instance_eval(&block)
|
19
|
+
end
|
20
|
+
|
21
|
+
alias :plans :roles
|
22
|
+
|
23
|
+
def asserts(&block)
|
24
|
+
builder = AssertsBuilder.new(schema)
|
25
|
+
builder.instance_eval(&block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def namespace(name, &block)
|
29
|
+
namespace = Namespace.new(name.to_sym)
|
30
|
+
builder = NamespaceBuilder.new(namespace)
|
31
|
+
builder.instance_eval(&block)
|
32
|
+
schema.add_namespace(namespace)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AccessSchema
|
2
|
+
class Element
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(name, roles, &block)
|
6
|
+
@name = name
|
7
|
+
@roles = roles
|
8
|
+
@block = block
|
9
|
+
@expectations = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_expectation(expectation)
|
13
|
+
@expectations << expectation
|
14
|
+
end
|
15
|
+
|
16
|
+
def allow?(role)
|
17
|
+
@roles.include?(role) || begin
|
18
|
+
checklist = @expectations.select { |exp| exp.for?(role) }
|
19
|
+
checklist.length > 0 && checklist.all? { |exp| yield(exp) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AccessSchema
|
2
|
+
class Expectation
|
3
|
+
attr_reader :name
|
4
|
+
attr_reader :roles
|
5
|
+
attr_reader :options
|
6
|
+
|
7
|
+
def initialize(name, roles, options)
|
8
|
+
@name = name
|
9
|
+
@roles = roles
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def for?(role)
|
14
|
+
@roles.include?(role)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module AccessSchema
|
2
|
+
class Proxy
|
3
|
+
|
4
|
+
def initialize(schema, options)
|
5
|
+
@schema = schema
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def allow?(*args)
|
10
|
+
namespace = args[0]
|
11
|
+
feature = args[1]
|
12
|
+
role, options = case args[2]
|
13
|
+
when Symbol, String
|
14
|
+
[args[2], args[3]]
|
15
|
+
else
|
16
|
+
[@options[:role] || @options[:plan], args[2]]
|
17
|
+
end
|
18
|
+
|
19
|
+
@schema.allow?(namespace, feature, role, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def require!(*args)
|
23
|
+
@schema.require!(*args)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module AccessSchema
|
2
|
+
class Schema
|
3
|
+
|
4
|
+
attr_reader :roles
|
5
|
+
alias :plans :roles
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@roles = []
|
9
|
+
@asserts = {}
|
10
|
+
@namespaces = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_role(role)
|
14
|
+
@roles << role
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_assert(assert)
|
18
|
+
@asserts[assert.name] = assert
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_namespace(namespace)
|
22
|
+
@namespaces[namespace.name] = namespace
|
23
|
+
end
|
24
|
+
|
25
|
+
def allow?(*args)
|
26
|
+
require!(*args)
|
27
|
+
rescue NotAlowedError => e
|
28
|
+
false
|
29
|
+
else
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def require!(*args)
|
34
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
35
|
+
case args[0]
|
36
|
+
when String, Symbol
|
37
|
+
check!(args[0].to_sym, args[1].to_sym, args[2].to_sym, options)
|
38
|
+
else
|
39
|
+
check!(args[0].class.name.to_sym, args[1].to_sym, args[2].to_sym, options.merge(:subject => args[0]) )
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def check!(namespace_name, element_name, role, options)
|
46
|
+
|
47
|
+
allowed = for_element(namespace_name, element_name) do |element|
|
48
|
+
element.allow?(role) do |expectation|
|
49
|
+
check_assert(expectation, options)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
unless allowed
|
54
|
+
raise NotAlowedError.new
|
55
|
+
else
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
def check_assert(expectation, options)
|
62
|
+
@asserts[expectation.name].check?(expectation.options.merge(options))
|
63
|
+
end
|
64
|
+
|
65
|
+
def for_element(namespace, element)
|
66
|
+
ns = namespace.to_sym
|
67
|
+
fn = element.to_sym
|
68
|
+
allowed = elements_for(ns).any? do |element|
|
69
|
+
if element.name == fn
|
70
|
+
yield(element)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def elements_for(namespace)
|
76
|
+
@namespaces[namespace].elements
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'access_schema/version'
|
2
|
+
require 'access_schema/exceptions'
|
3
|
+
|
4
|
+
require 'access_schema/schema'
|
5
|
+
require 'access_schema/assert'
|
6
|
+
require 'access_schema/namespace'
|
7
|
+
require 'access_schema/element'
|
8
|
+
require 'access_schema/expectation'
|
9
|
+
|
10
|
+
require 'access_schema/builders/basic_builder'
|
11
|
+
require 'access_schema/builders/roles_builder'
|
12
|
+
require 'access_schema/builders/asserts_builder'
|
13
|
+
require 'access_schema/builders/namespace_builder'
|
14
|
+
require 'access_schema/builders/element_builder'
|
15
|
+
require 'access_schema/builders/schema_builder'
|
16
|
+
|
17
|
+
require 'access_schema/proxy'
|
18
|
+
|
19
|
+
module AccessSchema
|
20
|
+
|
21
|
+
def self.build(*args)
|
22
|
+
SchemaBuilder.build(*args)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.build_file(*args)
|
26
|
+
SchemaBuilder.build_file(*args)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.with_options(schema, options)
|
30
|
+
Proxy.new(schema, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AccessSchema do
|
4
|
+
|
5
|
+
describe "#build" do
|
6
|
+
it "returns schema"
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#build_file" do
|
10
|
+
it "returns schema"
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#with_options" do
|
14
|
+
|
15
|
+
before do
|
16
|
+
@schema = AccessSchema.build_file('spec/schema_example.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "takes schema and options" do
|
20
|
+
lambda {
|
21
|
+
AccessSchema.with_options(@schema, {:plan => :none})
|
22
|
+
}.should_not raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns schema" do
|
26
|
+
result = AccessSchema.with_options(@schema, {:plan => :none})
|
27
|
+
%w{allow? require!}.should be_all{|m| result.respond_to?(m)}
|
28
|
+
end
|
29
|
+
|
30
|
+
it "allows to not specify plan for schema calls" do
|
31
|
+
schema = AccessSchema.with_options(@schema, {:plan => :flower})
|
32
|
+
schema.allow?("Review", :mark_featured).should be_true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "but it accepts plan too" do
|
36
|
+
schema = AccessSchema.with_options(@schema, {})
|
37
|
+
schema.allow?("Review", :mark_featured, :flower).should be_true
|
38
|
+
schema.allow?("Review", :mark_featured, :none).should be_false
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
File without changes
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AccessSchema::SchemaBuilder do
|
4
|
+
|
5
|
+
before do
|
6
|
+
end
|
7
|
+
|
8
|
+
it "builds schema from block" do
|
9
|
+
@schema = AccessSchema::SchemaBuilder.build do
|
10
|
+
plans do
|
11
|
+
plan :none
|
12
|
+
end
|
13
|
+
end
|
14
|
+
@schema.should be
|
15
|
+
end
|
16
|
+
|
17
|
+
it "builds schema from file" do
|
18
|
+
@schema = AccessSchema::SchemaBuilder.build_file('spec/schema_example.rb')
|
19
|
+
@schema.should be
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises error if file dows not exists" do
|
23
|
+
lambda { @schema = AccessSchema::SchemaBuilder.build_file('abc') }.should raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
class Review; end
|
30
|
+
|
31
|
+
describe AccessSchema::SchemaBuilder, "produced schema example" do
|
32
|
+
|
33
|
+
before do
|
34
|
+
@review = Review.new
|
35
|
+
@review.stub(:photos_count) { @photo_count }
|
36
|
+
@schema = AccessSchema::SchemaBuilder.build_file('spec/schema_example.rb')
|
37
|
+
end
|
38
|
+
|
39
|
+
it "creates plans" do
|
40
|
+
@schema.plans.should == [:none, :bulb, :flower, :bouquet]
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when checking against plan 'none'" do
|
44
|
+
|
45
|
+
it "does not allows to mark featured" do
|
46
|
+
@schema.allow?(@review, :mark_featured, :none).should be_false
|
47
|
+
end
|
48
|
+
|
49
|
+
it "allows to add first photo" do
|
50
|
+
@photo_count = 0
|
51
|
+
@schema.allow?(@review, :add_photo, :none).should be_true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "does not allow to add second one" do
|
55
|
+
@photo_count = 1
|
56
|
+
@schema.allow?(@review, :add_photo, :none).should be_false
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when checking against plan 'bulb'" do
|
62
|
+
|
63
|
+
it "does not allow to mark featured" do
|
64
|
+
@schema.allow?(@review, :mark_featured, :bulb).should be_false
|
65
|
+
end
|
66
|
+
|
67
|
+
it "allows to add up to 5 photos" do
|
68
|
+
@photo_count = 4
|
69
|
+
@schema.allow?(@review, :add_photo, :bulb).should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "does not allow to add more then 5" do
|
73
|
+
@photo_count = 5
|
74
|
+
@schema.allow?(@review, :add_photo, :bulb).should be_false
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when checking against plan 'flower'" do
|
80
|
+
|
81
|
+
it "allows to mark featured" do
|
82
|
+
@schema.allow?(@review, :mark_featured, :flower).should be_true
|
83
|
+
end
|
84
|
+
|
85
|
+
it "allows to add up to 10 photos" do
|
86
|
+
@photo_count = 9
|
87
|
+
@schema.allow?(@review, :add_photo, :flower).should be_true
|
88
|
+
end
|
89
|
+
|
90
|
+
it "does not allow to add more then 10" do
|
91
|
+
@photo_count = 10
|
92
|
+
@schema.allow?(@review, :add_photo, :flower).should be_false
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when checking against plan 'bouquet'" do
|
98
|
+
|
99
|
+
it "allows to mark featured" do
|
100
|
+
@schema.allow?(@review, :mark_featured, :bouquet).should be_true
|
101
|
+
end
|
102
|
+
|
103
|
+
it "allows to add over 9000 photos" do
|
104
|
+
@photo_count = 9000
|
105
|
+
@schema.allow?(@review, :add_photo, :bouquet).should be_true
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AccessSchema::Schema, "errors rising" do
|
4
|
+
|
5
|
+
describe "#add_plan" do
|
6
|
+
|
7
|
+
it "raises error if duplicate"
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#add_assert" do
|
12
|
+
|
13
|
+
it "raises error if duplicate"
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#add_feature" do
|
18
|
+
|
19
|
+
it "raises error if duplicate"
|
20
|
+
it "raises error for invalid plan"
|
21
|
+
it "raises error for invalid assert"
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#allow?" do
|
26
|
+
|
27
|
+
it "raises exception on invalid namespace"
|
28
|
+
it "raises exception on invalid feature"
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#require!" do
|
33
|
+
|
34
|
+
it "raises en error is feature is nt allowed"
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
plans do
|
3
|
+
plan :none
|
4
|
+
plan :bulb
|
5
|
+
plan :flower
|
6
|
+
plan :bouquet
|
7
|
+
end
|
8
|
+
|
9
|
+
asserts do
|
10
|
+
|
11
|
+
assert :photo_limit, [:limit] do
|
12
|
+
subject.photos_count < limit
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
namespace "Review" do
|
18
|
+
|
19
|
+
feature :mark_featured, [:flower, :bouquet]
|
20
|
+
|
21
|
+
feature :add_photo, [:bouquet] do
|
22
|
+
assert :photo_limit, [:none], :limit => 1
|
23
|
+
assert :photo_limit, [:bulb], :limit => 5
|
24
|
+
assert :photo_limit, [:flower], :limit => 10
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: access_schema
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Victor Gumayunov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-27 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: AccessSchema is a tool for ACL or tariff plans schema definition and
|
15
|
+
checks
|
16
|
+
email:
|
17
|
+
- gumayunov@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- .rspec
|
24
|
+
- Gemfile
|
25
|
+
- Guardfile
|
26
|
+
- LICENSE
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- access_schema.gemspec
|
30
|
+
- lib/access_schema.rb
|
31
|
+
- lib/access_schema/assert.rb
|
32
|
+
- lib/access_schema/builders/asserts_builder.rb
|
33
|
+
- lib/access_schema/builders/basic_builder.rb
|
34
|
+
- lib/access_schema/builders/element_builder.rb
|
35
|
+
- lib/access_schema/builders/namespace_builder.rb
|
36
|
+
- lib/access_schema/builders/roles_builder.rb
|
37
|
+
- lib/access_schema/builders/schema_builder.rb
|
38
|
+
- lib/access_schema/element.rb
|
39
|
+
- lib/access_schema/exceptions.rb
|
40
|
+
- lib/access_schema/expectation.rb
|
41
|
+
- lib/access_schema/namespace.rb
|
42
|
+
- lib/access_schema/proxy.rb
|
43
|
+
- lib/access_schema/schema.rb
|
44
|
+
- lib/access_schema/version.rb
|
45
|
+
- spec/access_schema_spec.rb
|
46
|
+
- spec/assess_schema/proxy_spec.rb
|
47
|
+
- spec/assess_schema/schema_builder_spec.rb
|
48
|
+
- spec/assess_schema/schema_spec.rb
|
49
|
+
- spec/schema_example.rb
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
homepage: ''
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project: access_schema
|
71
|
+
rubygems_version: 1.8.16
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: AccessSchema is an ACL tool
|
75
|
+
test_files:
|
76
|
+
- spec/access_schema_spec.rb
|
77
|
+
- spec/assess_schema/proxy_spec.rb
|
78
|
+
- spec/assess_schema/schema_builder_spec.rb
|
79
|
+
- spec/assess_schema/schema_spec.rb
|
80
|
+
- spec/schema_example.rb
|
81
|
+
- spec/spec_helper.rb
|