access_policy 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/access_policy.rb +2 -2
- data/lib/access_policy/version.rb +1 -1
- data/spec/integration/lib/access_policy_spec.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d51db3ea65aec0cc8750fb55cc8c89366fab2e8
|
4
|
+
data.tar.gz: 074fa237875c2d5604196978c72c4640d6775c44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb5da0d85c395208135b3d80d1f9ede490d841f1e05591e1b5353f27ccd48c53774d74806c78e76712d456d1b40a4571a2f3981b05e87988768d39d96a1e5007
|
7
|
+
data.tar.gz: 3e30ee36034e37de353476ab318528fcbe26b0f5bebf0526adc5114beb3cf5af5b32de5b52cb16bb1cc36359a843e297319472878ffeed8be650a46ee898817b
|
data/README.md
CHANGED
data/lib/access_policy.rb
CHANGED
@@ -43,11 +43,11 @@ module AccessPolicy
|
|
43
43
|
|
44
44
|
module ClassMethods
|
45
45
|
|
46
|
-
def policy_guarded_method(action_name,
|
46
|
+
def policy_guarded_method(action_name, query="#{action_name}?" ,&block)
|
47
47
|
unsafe_action_name = unsafe_action_name(action_name)
|
48
48
|
|
49
49
|
define_method action_name do |*args|
|
50
|
-
_authorize
|
50
|
+
_authorize query
|
51
51
|
self.send(unsafe_action_name, *args)
|
52
52
|
end
|
53
53
|
|
@@ -5,6 +5,10 @@ module AccessPolicySpec
|
|
5
5
|
def call?
|
6
6
|
current_user && current_user.allowed?
|
7
7
|
end
|
8
|
+
|
9
|
+
def query?
|
10
|
+
raise StandardError, 'query? called'
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
|
@@ -15,6 +19,10 @@ module AccessPolicySpec
|
|
15
19
|
:return_value
|
16
20
|
end
|
17
21
|
|
22
|
+
policy_guarded_method 'other_method_name', 'query?' do
|
23
|
+
:return_value
|
24
|
+
end
|
25
|
+
|
18
26
|
end
|
19
27
|
end
|
20
28
|
|
@@ -63,6 +71,12 @@ describe AccessPolicy do
|
|
63
71
|
subject.call_unsafe
|
64
72
|
}.not_to raise_error
|
65
73
|
end
|
74
|
+
|
75
|
+
it 'uses a different name for query when wanted' do
|
76
|
+
expect {
|
77
|
+
subject.other_method_name
|
78
|
+
}.to raise_error(StandardError, 'query? called')
|
79
|
+
end
|
66
80
|
end
|
67
81
|
|
68
82
|
describe '.with_user_or_role' do
|