pundit-matchers 1.3.1 → 1.4.0
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 +4 -4
- data/lib/pundit/matchers.rb +18 -28
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa9d9639180168e0aa248c00f916e8711b0e82a3
|
4
|
+
data.tar.gz: 2e70263fd7ca377531a0c34e6136dc0e4ed9f80d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a5ebc0298d666b8b19884710386fe194f114acd2e7724468286032f516f9a522a13418baba5c5b0e93294000dbbe1f190a0b20e5a1646537ffe5aed28eab0fd
|
7
|
+
data.tar.gz: c2e2e029245a9e6d52b200905653a9acb092ba23abe481bc1f686364bae5171eeeebc580dc379cad9004f93db9925864579d862f9b551971bc8e43c3f019e67b
|
data/lib/pundit/matchers.rb
CHANGED
@@ -26,28 +26,24 @@ module Pundit
|
|
26
26
|
RSpec::Matchers.define :forbid_actions do |actions|
|
27
27
|
match do |policy|
|
28
28
|
return false if actions.count < 2
|
29
|
-
actions.
|
30
|
-
|
29
|
+
@allowed_actions = actions.select do |action|
|
30
|
+
policy.public_send("#{action}?")
|
31
31
|
end
|
32
|
-
|
32
|
+
@allowed_actions.empty?
|
33
33
|
end
|
34
34
|
|
35
|
+
attr_reader :allowed_actions
|
36
|
+
|
35
37
|
zero_actions_failure_message = 'At least two actions must be ' \
|
36
38
|
'specified when using the forbid_actions matcher.'
|
37
39
|
|
38
|
-
one_action_failure_message = 'More than one action must be specified ' \
|
39
|
-
'when using the forbid_actions matcher. To test a single action, use ' \
|
40
|
-
'forbid_action instead.'
|
41
|
-
|
42
40
|
failure_message do |policy|
|
43
41
|
case actions.count
|
44
42
|
when 0
|
45
43
|
zero_actions_failure_message
|
46
|
-
when 1
|
47
|
-
one_action_failure_message
|
48
44
|
else
|
49
|
-
"#{policy.class}
|
50
|
-
"#{policy.user.inspect}."
|
45
|
+
"#{policy.class} expected to forbid #{actions}, but allowed " \
|
46
|
+
"#{allowed_actions} for #{policy.user.inspect}."
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
@@ -55,11 +51,9 @@ module Pundit
|
|
55
51
|
case actions.count
|
56
52
|
when 0
|
57
53
|
zero_actions_failure_message
|
58
|
-
when 1
|
59
|
-
one_action_failure_message
|
60
54
|
else
|
61
|
-
"#{policy.class}
|
62
|
-
"#{policy.user.inspect}."
|
55
|
+
"#{policy.class} expected to permit #{actions}, but forbade " \
|
56
|
+
"#{allowed_actions} for #{policy.user.inspect}."
|
63
57
|
end
|
64
58
|
end
|
65
59
|
end
|
@@ -155,28 +149,24 @@ module Pundit
|
|
155
149
|
RSpec::Matchers.define :permit_actions do |actions|
|
156
150
|
match do |policy|
|
157
151
|
return false if actions.count < 2
|
158
|
-
actions.
|
159
|
-
|
152
|
+
@forbidden_actions = actions.reject do |action|
|
153
|
+
policy.public_send("#{action}?")
|
160
154
|
end
|
161
|
-
|
155
|
+
@forbidden_actions.empty?
|
162
156
|
end
|
163
157
|
|
158
|
+
attr_reader :forbidden_actions
|
159
|
+
|
164
160
|
zero_actions_failure_message = 'At least two actions must be ' \
|
165
161
|
'specified when using the permit_actions matcher.'
|
166
162
|
|
167
|
-
one_action_failure_message = 'More than one action must be specified ' \
|
168
|
-
'when using the permit_actions matcher. To test a single action, use ' \
|
169
|
-
'permit_action instead.'
|
170
|
-
|
171
163
|
failure_message do |policy|
|
172
164
|
case actions.count
|
173
165
|
when 0
|
174
166
|
zero_actions_failure_message
|
175
|
-
when 1
|
176
|
-
one_action_failure_message
|
177
167
|
else
|
178
|
-
"#{policy.class}
|
179
|
-
"#{policy.user.inspect}."
|
168
|
+
"#{policy.class} expected to permit #{actions}, but forbade " \
|
169
|
+
"#{forbidden_actions} for #{policy.user.inspect}."
|
180
170
|
end
|
181
171
|
end
|
182
172
|
|
@@ -187,8 +177,8 @@ module Pundit
|
|
187
177
|
when 1
|
188
178
|
one_action_failure_message
|
189
179
|
else
|
190
|
-
"#{policy.class}
|
191
|
-
"#{policy.user.inspect}."
|
180
|
+
"#{policy.class} expected to forbid #{actions}, but allowed " \
|
181
|
+
"#{forbidden_actions} for #{policy.user.inspect}."
|
192
182
|
end
|
193
183
|
end
|
194
184
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pundit-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Alley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pundit
|
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
73
|
rubyforge_project:
|
74
|
-
rubygems_version: 2.
|
74
|
+
rubygems_version: 2.6.14
|
75
75
|
signing_key:
|
76
76
|
specification_version: 4
|
77
77
|
summary: RSpec matchers for Pundit policies
|