consent 0.3.1 → 0.4
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 +5 -5
- data/.ruby-version +1 -0
- data/TODO.md +1 -0
- data/consent.gemspec +1 -1
- data/lib/consent.rb +23 -2
- data/lib/consent/permissions.rb +1 -1
- data/lib/consent/rspec.rb +5 -19
- data/lib/consent/version.rb +1 -1
- data/lib/generators/consent/permissions_generator.rb +2 -0
- data/lib/generators/consent/templates/permissions_spec.rb.erb +18 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 81dca1628aeb1c52c3d9d3b892e3c148a9556bf2a2c0c5199ddd6c160155897a
|
4
|
+
data.tar.gz: 3e77560cbe9f555e8f8edd42186b3e61b5b2617aa5cc040255bbf9d42c25dbc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a4b2b6f8d4b797fbe2b7ce0c272f2bd968fcfb059f0545ff31b230ecd0ea62bf0a198940160dab1c494295f08b149fb0b553903896089a0ff93fe8ab45bdce2
|
7
|
+
data.tar.gz: 639e12a757f9708cb063d20e77ebbf3d89029811f73e1c7b8730437029aab729d2c4edfa296ce208860c8eca96781b24dd1460425a3d77d5831c5d45166e492a
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.0
|
data/TODO.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* DSL validate Consent state
|
data/consent.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_development_dependency 'activesupport', '~> 3.2.22'
|
21
21
|
spec.add_development_dependency 'cancancan', '~> 1.15.0'
|
22
|
-
spec.add_development_dependency 'bundler', '~>
|
22
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
23
23
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
24
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
25
|
end
|
data/lib/consent.rb
CHANGED
@@ -16,7 +16,28 @@ module Consent
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.subjects
|
19
|
-
@subjects ||=
|
19
|
+
@subjects ||= []
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.find_subjects(subject_key)
|
23
|
+
@subjects.find do |subject|
|
24
|
+
subject.key.eql?(subject_key)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.find_action(subject_key, action_key)
|
29
|
+
Consent.find_subjects(subject_key)
|
30
|
+
.map(&:actions).flatten
|
31
|
+
.find do |action|
|
32
|
+
action.key.eql?(action_key)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.find_view(subject_key, view_key)
|
37
|
+
views = Consent.find_subjects(subject_key)
|
38
|
+
.map{|subject| subject.views}
|
39
|
+
.reduce({}, &:merge)
|
40
|
+
views[view_key]
|
20
41
|
end
|
21
42
|
|
22
43
|
def self.load_subjects!(paths)
|
@@ -26,7 +47,7 @@ module Consent
|
|
26
47
|
|
27
48
|
def self.define(key, label, options = {}, &block)
|
28
49
|
defaults = options.fetch(:defaults, {})
|
29
|
-
subjects
|
50
|
+
subjects << Subject.new(key, label).tap do |subject|
|
30
51
|
DSL.build(subject, defaults, &block)
|
31
52
|
end
|
32
53
|
end
|
data/lib/consent/permissions.rb
CHANGED
data/lib/consent/rspec.rb
CHANGED
@@ -4,32 +4,18 @@ module Consent
|
|
4
4
|
module Rspec
|
5
5
|
extend RSpec::Matchers::DSL
|
6
6
|
|
7
|
-
def get_view(subject_key, view_key)
|
8
|
-
Consent.subjects[subject_key].try(:views).try(:[], view_key)
|
9
|
-
end
|
10
|
-
|
11
|
-
def get_action(subject_key, action_key)
|
12
|
-
(Consent.subjects[subject_key].try(:actions) || []).find do |action|
|
13
|
-
action.key.eql?(action_key)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def get_action_view_keys(subject_key, action_key)
|
18
|
-
(get_action(subject_key, action_key).try(:options).try(:[], :views) || []).map(&:key)
|
19
|
-
end
|
20
|
-
|
21
7
|
matcher :consent_action do |action_key|
|
22
8
|
chain :with_views do |*views|
|
23
9
|
@views = views
|
24
10
|
end
|
25
11
|
|
26
12
|
match do |subject_key|
|
27
|
-
action =
|
13
|
+
action = Consent.find_action(subject_key, action_key)
|
28
14
|
action && @views ? action.view_keys.sort.eql?(@views.sort) : !action.nil?
|
29
15
|
end
|
30
16
|
|
31
17
|
failure_message do |subject_key|
|
32
|
-
action =
|
18
|
+
action = Consent.find_action(subject_key, action_key)
|
33
19
|
message = "expected %s (%s) to provide action %s" % [
|
34
20
|
subject_key.to_s, subject.class, action_key
|
35
21
|
]
|
@@ -48,12 +34,12 @@ module Consent
|
|
48
34
|
end
|
49
35
|
|
50
36
|
match do |subject_key|
|
51
|
-
view =
|
37
|
+
view = Consent.find_view(subject_key, view_key)
|
52
38
|
conditions ? view.try(:conditions, *@context).eql?(conditions) : !view.nil?
|
53
39
|
end
|
54
40
|
|
55
41
|
failure_message do |subject_key|
|
56
|
-
view =
|
42
|
+
view = Consent.find_view(subject_key, view_key)
|
57
43
|
message = "expected %s (%s) to provide view %s with %p, but" % [
|
58
44
|
subject_key.to_s, subject.class, view_key, conditions
|
59
45
|
]
|
@@ -62,7 +48,7 @@ module Consent
|
|
62
48
|
actual_conditions = view.conditions(*@context)
|
63
49
|
'%s conditions are %p' % [message, actual_conditions]
|
64
50
|
else
|
65
|
-
actual_views = Consent.
|
51
|
+
actual_views = Consent.find_subjects(subject_key).map(&:views).map(&:keys).flatten
|
66
52
|
'%s available views are %p' % [message, actual_views]
|
67
53
|
end
|
68
54
|
end
|
data/lib/consent/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe '<%= @name %> permissions', type: :permissions do
|
4
|
+
subject { <%= @name %> }
|
5
|
+
# Define the user to be spec'ed
|
6
|
+
#
|
7
|
+
# let(:user) { double(entity_ids: [1, 2]) }
|
8
|
+
|
9
|
+
# Define consent expectations for views
|
10
|
+
#
|
11
|
+
# it { is_expected.to consent_view(:entity, {entity_id: [1, 2]}).to(user) }
|
12
|
+
|
13
|
+
# Define consent expectations for actions
|
14
|
+
#
|
15
|
+
# it { is_expected.to consent_action(:read) }
|
16
|
+
# it { is_expected.to consent_action(:update) }
|
17
|
+
# it { is_expected.to consent_action(:create) }
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Palhares
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,10 +89,12 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
|
+
- ".ruby-version"
|
92
93
|
- ".travis.yml"
|
93
94
|
- Gemfile
|
94
95
|
- README.md
|
95
96
|
- Rakefile
|
97
|
+
- TODO.md
|
96
98
|
- bin/console
|
97
99
|
- bin/setup
|
98
100
|
- consent.gemspec
|
@@ -109,6 +111,7 @@ files:
|
|
109
111
|
- lib/consent/view.rb
|
110
112
|
- lib/generators/consent/permissions_generator.rb
|
111
113
|
- lib/generators/consent/templates/permissions.rb.erb
|
114
|
+
- lib/generators/consent/templates/permissions_spec.rb.erb
|
112
115
|
homepage:
|
113
116
|
licenses: []
|
114
117
|
metadata: {}
|
@@ -128,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
131
|
version: '0'
|
129
132
|
requirements: []
|
130
133
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
134
|
+
rubygems_version: 2.7.3
|
132
135
|
signing_key:
|
133
136
|
specification_version: 4
|
134
137
|
summary: Consent
|