pundit-matchers 1.6.0 → 1.7.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 +5 -5
- data/lib/pundit/matchers.rb +24 -2
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b0da80bb866c35b8ab6548d017a9bc022831e3da0c5493b99aac0ba5c8c79cad
|
4
|
+
data.tar.gz: 24bfacd140e3976e30c88204db5e33566c42dbd5e45d568c8d857a7a4205951d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c1fbddf259fce9fa65c6f0613ec5d46e271ab0c7212380bc86cb5fef6fb85a2f74b6c20a4fb6b4c0e1dacc6b8ad11e1c963f8827c997e88bb319cce157d305b
|
7
|
+
data.tar.gz: a2363786904df0631c54b8d84094179b61607e300a16ba53cd6406b02272e51f1e21060832f5b64a3eeaaba1ff6dba7c8462d3308732f335dc363df666058120
|
data/lib/pundit/matchers.rb
CHANGED
@@ -43,7 +43,8 @@ module Pundit
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
RSpec::Matchers.define :forbid_actions do
|
46
|
+
RSpec::Matchers.define :forbid_actions do |*actions|
|
47
|
+
actions.flatten!
|
47
48
|
match do |policy|
|
48
49
|
return false if actions.count < 1
|
49
50
|
@allowed_actions = actions.select do |action|
|
@@ -204,7 +205,8 @@ module Pundit
|
|
204
205
|
end
|
205
206
|
end
|
206
207
|
|
207
|
-
RSpec::Matchers.define :permit_actions do
|
208
|
+
RSpec::Matchers.define :permit_actions do |*actions|
|
209
|
+
actions.flatten!
|
208
210
|
match do |policy|
|
209
211
|
return false if actions.count < 1
|
210
212
|
@forbidden_actions = actions.reject do |action|
|
@@ -213,6 +215,26 @@ module Pundit
|
|
213
215
|
@forbidden_actions.empty?
|
214
216
|
end
|
215
217
|
|
218
|
+
match_when_negated do |policy|
|
219
|
+
::Kernel.warn 'Using expect { }.not_to permit_actions could produce \
|
220
|
+
confusing results. Please use `.to forbid_actions` instead. To \
|
221
|
+
clarify, `.not_to permit_actions` will look at all of the actions and \
|
222
|
+
checks if ANY actions fail, not if all actions fail. Therefore, you \
|
223
|
+
could result in something like this: \
|
224
|
+
|
225
|
+
it { is_expected.to permit_actions([:new, :create, :edit]) } \
|
226
|
+
it { is_expected.not_to permit_actions([:edit, :destroy]) } \
|
227
|
+
|
228
|
+
In this case, edit would be true and destroy would be false, but both \
|
229
|
+
tests would pass.'
|
230
|
+
|
231
|
+
return true if actions.count < 1
|
232
|
+
@forbidden_actions = actions.reject do |action|
|
233
|
+
policy.public_send("#{action}?")
|
234
|
+
end
|
235
|
+
!@forbidden_actions.empty?
|
236
|
+
end
|
237
|
+
|
216
238
|
attr_reader :forbidden_actions
|
217
239
|
|
218
240
|
zero_actions_failure_message = 'At least one action must be specified ' \
|
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.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Alley
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|
@@ -55,7 +55,7 @@ homepage: http://github.com/chrisalley/pundit-matchers
|
|
55
55
|
licenses:
|
56
56
|
- MIT
|
57
57
|
metadata: {}
|
58
|
-
post_install_message:
|
58
|
+
post_install_message:
|
59
59
|
rdoc_options: []
|
60
60
|
require_paths:
|
61
61
|
- lib
|
@@ -70,9 +70,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
|
-
|
74
|
-
|
75
|
-
signing_key:
|
73
|
+
rubygems_version: 3.2.15
|
74
|
+
signing_key:
|
76
75
|
specification_version: 4
|
77
76
|
summary: RSpec matchers for Pundit policies
|
78
77
|
test_files: []
|