admission 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +37 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/LICENSE +674 -0
- data/README.md +2 -0
- data/admission.gemspec +18 -0
- data/bin/rspec +8 -0
- data/lib/admission.rb +9 -0
- data/lib/admission/ability.rb +140 -0
- data/lib/admission/admission.rb +6 -0
- data/lib/admission/arbitration.rb +126 -0
- data/lib/admission/denied.rb +15 -0
- data/lib/admission/privilege.rb +129 -0
- data/lib/admission/rails.rb +94 -0
- data/lib/admission/resource_arbitration.rb +112 -0
- data/lib/admission/status.rb +38 -0
- data/lib/admission/version.rb +3 -0
- data/spec/integration/_helper.rb +2 -0
- data/spec/integration/action_arbitrating_spec.rb +119 -0
- data/spec/integration/resource_arbitrating_spec.rb +246 -0
- data/spec/rspec_config.rb +103 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/test_context/country.rb +24 -0
- data/spec/test_context/index.rb +7 -0
- data/spec/test_context/person.rb +31 -0
- data/spec/test_context/persons_fixtures.rb +43 -0
- data/spec/test_context/privileges_and_rules.rb +114 -0
- data/spec/unit/_helper.rb +1 -0
- data/spec/unit/ability_spec.rb +29 -0
- data/spec/unit/privilege/order_definer_spec.rb +184 -0
- data/spec/unit/privilege_spec.rb +146 -0
- data/spec/unit/request_arbitration_spec.rb +31 -0
- metadata +76 -0
@@ -0,0 +1,146 @@
|
|
1
|
+
require_relative '_helper'
|
2
|
+
|
3
|
+
RSpec.describe Admission::Privilege do
|
4
|
+
|
5
|
+
def new_privilege *args
|
6
|
+
Admission::Privilege.new *args
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:privilege){ new_privilege :man }
|
10
|
+
|
11
|
+
let(:privilege_superman){ new_privilege :superman }
|
12
|
+
let(:privilege_uberman){ new_privilege :uberman }
|
13
|
+
|
14
|
+
|
15
|
+
describe '#new' do
|
16
|
+
|
17
|
+
it 'create base privilege' do
|
18
|
+
expect(new_privilege :man).to have_attributes(name: :man, level: :base)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'creates with level' do
|
22
|
+
expect(new_privilege :man, :lvl1).to have_attributes(name: :man, level: :lvl1)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'changes names to symbols' do
|
26
|
+
expect(new_privilege 'man', 'lvl1').to have_attributes(name: :man, level: :lvl1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'hash is combination of name and level' do
|
30
|
+
expect(privilege.hash).to eq([:man, :base].hash)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
describe '#inherited' do
|
37
|
+
|
38
|
+
it 'nothing' do
|
39
|
+
expect(privilege.inherited).to be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'single item' do
|
43
|
+
privilege.inherits_from privilege_superman
|
44
|
+
expect(privilege.inherited).to contain_exactly(privilege_superman)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'arguments list' do
|
48
|
+
privilege.inherits_from privilege_superman, privilege_uberman
|
49
|
+
expect(privilege.inherited).to contain_exactly(privilege_superman, privilege_uberman)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
describe '#eql?' do
|
56
|
+
|
57
|
+
it 'compares by hash' do
|
58
|
+
p1 = new_privilege :man
|
59
|
+
p2 = new_privilege :man
|
60
|
+
expect(p1).to eql(p2)
|
61
|
+
|
62
|
+
p2.instance_variable_set :@hash, nil.hash
|
63
|
+
expect(p1).not_to eql(p2)
|
64
|
+
|
65
|
+
expect(p1).not_to eql(new_privilege :self)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
describe '#to_s' do
|
72
|
+
|
73
|
+
it 'prints name and level' do
|
74
|
+
expect(privilege.to_s).to eq('<Privilege key=man>')
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'prints inheritance' do
|
78
|
+
privilege_superman.inherits_from privilege
|
79
|
+
expect(privilege_superman.to_s).to eq(
|
80
|
+
'<Privilege key=superman inherited=[man]>'
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
describe '#dup_with_context' do
|
88
|
+
|
89
|
+
it 'self when context is empty' do
|
90
|
+
p2 = privilege.dup_with_context
|
91
|
+
expect(p2).to be_a(Admission::Privilege)
|
92
|
+
expect(p2).to equal(privilege)
|
93
|
+
|
94
|
+
p2 = privilege.dup_with_context nil
|
95
|
+
expect(p2).to be_a(Admission::Privilege)
|
96
|
+
expect(p2).to equal(privilege)
|
97
|
+
|
98
|
+
p2 = privilege.dup_with_context []
|
99
|
+
expect(p2).to be_a(Admission::Privilege)
|
100
|
+
expect(p2).to equal(privilege)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'duplicates with context as array' do
|
104
|
+
p2 = privilege.dup_with_context :moon
|
105
|
+
expect(p2).to be_a(Admission::Privilege)
|
106
|
+
expect(p2).not_to equal(privilege)
|
107
|
+
expect(p2).to eql(privilege)
|
108
|
+
expect(p2).to have_attributes(name: :man, level: :base, context: [:moon])
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'duplicates only change context' do
|
112
|
+
p2 = privilege.dup_with_context [:moon]
|
113
|
+
expect(p2).to be_a(Admission::Privilege)
|
114
|
+
expect(p2).not_to equal(privilege)
|
115
|
+
expect(p2).to eql(privilege)
|
116
|
+
expect(p2).to have_attributes(name: :man, level: :base, context: [:moon])
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
describe '.get_from_order' do
|
123
|
+
|
124
|
+
it 'returns nil for bad name' do
|
125
|
+
index = Admission::Privilege::OrderDefiner.define{ privilege :man }
|
126
|
+
expect(Admission::Privilege.get_from_order index, :woman).to be_nil
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'returns base privilege' do
|
130
|
+
index = Admission::Privilege::OrderDefiner.define{ privilege :man }
|
131
|
+
expect(Admission::Privilege.get_from_order index, :man).to be_eql(privilege)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'returns specific level privilege' do
|
135
|
+
index = Admission::Privilege::OrderDefiner.define{ privilege :vassal, levels: %i[lord] }
|
136
|
+
expect(Admission::Privilege.get_from_order index, :vassal, :lord).to be_eql(new_privilege :vassal, :lord)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'returns nil for bad level' do
|
140
|
+
index = Admission::Privilege::OrderDefiner.define{ privilege :vassal, levels: %i[lord] }
|
141
|
+
expect(Admission::Privilege.get_from_order index, :vassal, :pope).to be_nil
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# require_relative '../spec_helper'
|
2
|
+
# require_relative '../test_context/index'
|
3
|
+
#
|
4
|
+
# RSpec.describe Admission::RequestArbitration do
|
5
|
+
#
|
6
|
+
# # let(:nobody_ability){ Admission::Ability.new Person::FIXTURES[:nobody] }
|
7
|
+
# # let(:haramber_ability){ Admission::Ability.new Person::FIXTURES[:harambe] }
|
8
|
+
#
|
9
|
+
# def arbitration person_name, request
|
10
|
+
# person = Person::FIXTURES[person_name]
|
11
|
+
# Admission::RequestArbitration.new person, request
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
#
|
15
|
+
#
|
16
|
+
#
|
17
|
+
# describe '#new' do
|
18
|
+
#
|
19
|
+
#
|
20
|
+
#
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# describe '#prepare_sitting' do
|
24
|
+
#
|
25
|
+
# it 'sets context and clears decisions cache' do
|
26
|
+
#
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: admission
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- doooby
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: update-me
|
14
|
+
email: zelazk.o@email.cz
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".gitignore"
|
20
|
+
- ".rspec"
|
21
|
+
- ".ruby-version"
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- admission.gemspec
|
26
|
+
- bin/rspec
|
27
|
+
- lib/admission.rb
|
28
|
+
- lib/admission/ability.rb
|
29
|
+
- lib/admission/admission.rb
|
30
|
+
- lib/admission/arbitration.rb
|
31
|
+
- lib/admission/denied.rb
|
32
|
+
- lib/admission/privilege.rb
|
33
|
+
- lib/admission/rails.rb
|
34
|
+
- lib/admission/resource_arbitration.rb
|
35
|
+
- lib/admission/status.rb
|
36
|
+
- lib/admission/version.rb
|
37
|
+
- spec/integration/_helper.rb
|
38
|
+
- spec/integration/action_arbitrating_spec.rb
|
39
|
+
- spec/integration/resource_arbitrating_spec.rb
|
40
|
+
- spec/rspec_config.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
- spec/test_context/country.rb
|
43
|
+
- spec/test_context/index.rb
|
44
|
+
- spec/test_context/person.rb
|
45
|
+
- spec/test_context/persons_fixtures.rb
|
46
|
+
- spec/test_context/privileges_and_rules.rb
|
47
|
+
- spec/unit/_helper.rb
|
48
|
+
- spec/unit/ability_spec.rb
|
49
|
+
- spec/unit/privilege/order_definer_spec.rb
|
50
|
+
- spec/unit/privilege_spec.rb
|
51
|
+
- spec/unit/request_arbitration_spec.rb
|
52
|
+
homepage: https://github.com/doooby/admission
|
53
|
+
licenses:
|
54
|
+
- GPL-3.0
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.5.2
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: admission library
|
76
|
+
test_files: []
|