pundit-matchers 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pundit/matchers/utils/policy_info.rb +1 -1
- data/lib/pundit/matchers.rb +75 -97
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '013960778421a77229a9e50388f5cb7073cae3c60024b482f48c39431de063af'
|
4
|
+
data.tar.gz: 12a70d9a7ffdf1df5a2e584e555f3f934d36a971852605afa611c033a07c14dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c00b1be800433a24203f2d964a810eaa7445ed98934598726e568b727db2ad6333886d1d7dffe56196a1bb445a982c6d17ea96cda737cca5a5ca7e801445ada
|
7
|
+
data.tar.gz: 0fb59915496d8b6807b01b84ce6f70c2c350e5dd6db00851c1e013211fb6ab41c6a1cc2f21c11f0a10107f116dadd666ff71228bcf06eee1ed706a90b56d9550
|
@@ -14,7 +14,7 @@ module Pundit
|
|
14
14
|
def actions
|
15
15
|
@actions ||= begin
|
16
16
|
policy_methods = @policy.public_methods - Object.instance_methods
|
17
|
-
policy_methods.grep(/\?$/).map { |policy_method| policy_method.to_s.
|
17
|
+
policy_methods.grep(/\?$/).sort.map { |policy_method| policy_method.to_s.delete_suffix('?').to_sym }
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
data/lib/pundit/matchers.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rspec/core'
|
2
4
|
|
3
5
|
module Pundit
|
@@ -30,27 +32,25 @@ module Pundit
|
|
30
32
|
@configuration ||= Pundit::Matchers::Configuration.new
|
31
33
|
end
|
32
34
|
end
|
35
|
+
end
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
37
|
+
RSpec::Matchers.define :forbid_action do |action, *args, **kwargs|
|
38
|
+
match do |policy|
|
39
|
+
if args.any?
|
40
|
+
!policy.public_send("#{action}?", *args, **kwargs)
|
41
|
+
else
|
42
|
+
!policy.public_send("#{action}?", **kwargs)
|
41
43
|
end
|
44
|
+
end
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
46
|
+
failure_message do |policy|
|
47
|
+
"#{policy.class} does not forbid #{action} for " \
|
48
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
49
|
+
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
.inspect + '.'
|
53
|
-
end
|
51
|
+
failure_message_when_negated do |policy|
|
52
|
+
"#{policy.class} does not permit #{action} for " \
|
53
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -74,10 +74,9 @@ module Pundit
|
|
74
74
|
if actions.count.zero?
|
75
75
|
zero_actions_failure_message
|
76
76
|
else
|
77
|
-
"#{policy.class} expected to forbid #{actions}, but
|
78
|
-
|
79
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
80
|
-
.inspect + '.'
|
77
|
+
"#{policy.class} expected to forbid #{actions}, but permitted " \
|
78
|
+
"#{allowed_actions} for " \
|
79
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
81
80
|
end
|
82
81
|
end
|
83
82
|
|
@@ -86,9 +85,8 @@ module Pundit
|
|
86
85
|
zero_actions_failure_message
|
87
86
|
else
|
88
87
|
"#{policy.class} expected to permit #{actions}, but forbade " \
|
89
|
-
|
90
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
91
|
-
.inspect + '.'
|
88
|
+
"#{allowed_actions} for " \
|
89
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
92
90
|
end
|
93
91
|
end
|
94
92
|
end
|
@@ -99,15 +97,13 @@ module Pundit
|
|
99
97
|
end
|
100
98
|
|
101
99
|
failure_message do |policy|
|
102
|
-
"#{policy.class} does not forbid the edit or update action for "
|
103
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
104
|
-
.inspect + '.'
|
100
|
+
"#{policy.class} does not forbid the edit or update action for " \
|
101
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
105
102
|
end
|
106
103
|
|
107
104
|
failure_message_when_negated do |policy|
|
108
|
-
"#{policy.class} does not permit the edit or update action for "
|
109
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
110
|
-
.inspect + '.'
|
105
|
+
"#{policy.class} does not permit the edit or update action for " \
|
106
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
111
107
|
end
|
112
108
|
end
|
113
109
|
|
@@ -143,17 +139,15 @@ module Pundit
|
|
143
139
|
zero_attributes_failure_message
|
144
140
|
elsif defined? @action
|
145
141
|
"#{policy.class} expected to forbid the mass assignment of the " \
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
150
|
-
.inspect + '.'
|
142
|
+
"attributes #{attributes} when authorising the #{@action} action, " \
|
143
|
+
'but permitted the mass assignment of the attributes ' \
|
144
|
+
"#{allowed_attributes} for " \
|
145
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
151
146
|
else
|
152
147
|
"#{policy.class} expected to forbid the mass assignment of the " \
|
153
|
-
|
154
|
-
|
155
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
156
|
-
.inspect + '.'
|
148
|
+
"attributes #{attributes}, but permitted the mass assignment of " \
|
149
|
+
"the attributes #{allowed_attributes} for " \
|
150
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
157
151
|
end
|
158
152
|
end
|
159
153
|
|
@@ -162,17 +156,15 @@ module Pundit
|
|
162
156
|
zero_attributes_failure_message
|
163
157
|
elsif defined? @action
|
164
158
|
"#{policy.class} expected to permit the mass assignment of the " \
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
169
|
-
.inspect + '.'
|
159
|
+
"attributes #{attributes} when authorising the #{@action} action, " \
|
160
|
+
'but permitted the mass assignment of the attributes ' \
|
161
|
+
"#{allowed_attributes} for " \
|
162
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
170
163
|
else
|
171
164
|
"#{policy.class} expected to permit the mass assignment of the " \
|
172
|
-
|
173
|
-
|
174
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
175
|
-
.inspect + '.'
|
165
|
+
"attributes #{attributes}, but permitted the mass assignment of " \
|
166
|
+
"the attributes #{allowed_attributes} for " \
|
167
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
176
168
|
end
|
177
169
|
end
|
178
170
|
end
|
@@ -183,15 +175,13 @@ module Pundit
|
|
183
175
|
end
|
184
176
|
|
185
177
|
failure_message do |policy|
|
186
|
-
"#{policy.class} does not forbid the new or create action for "
|
187
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
188
|
-
.inspect + '.'
|
178
|
+
"#{policy.class} does not forbid the new or create action for " \
|
179
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
189
180
|
end
|
190
181
|
|
191
182
|
failure_message_when_negated do |policy|
|
192
|
-
"#{policy.class} does not permit the new or create action for "
|
193
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
194
|
-
.inspect + '.'
|
183
|
+
"#{policy.class} does not permit the new or create action for " \
|
184
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
195
185
|
end
|
196
186
|
end
|
197
187
|
|
@@ -205,15 +195,13 @@ module Pundit
|
|
205
195
|
end
|
206
196
|
|
207
197
|
failure_message do |policy|
|
208
|
-
"#{policy.class} does not permit #{action} for "
|
209
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
210
|
-
.inspect + '.'
|
198
|
+
"#{policy.class} does not permit #{action} for " \
|
199
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
211
200
|
end
|
212
201
|
|
213
202
|
failure_message_when_negated do |policy|
|
214
|
-
"#{policy.class} does not forbid #{action} for "
|
215
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
216
|
-
.inspect + '.'
|
203
|
+
"#{policy.class} does not forbid #{action} for " \
|
204
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
217
205
|
end
|
218
206
|
end
|
219
207
|
|
@@ -259,9 +247,8 @@ module Pundit
|
|
259
247
|
zero_actions_failure_message
|
260
248
|
else
|
261
249
|
"#{policy.class} expected to permit #{actions}, but forbade " \
|
262
|
-
|
263
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
264
|
-
.inspect + '.'
|
250
|
+
"#{forbidden_actions} for " \
|
251
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
265
252
|
end
|
266
253
|
end
|
267
254
|
|
@@ -269,10 +256,9 @@ module Pundit
|
|
269
256
|
if actions.count.zero?
|
270
257
|
zero_actions_failure_message
|
271
258
|
else
|
272
|
-
"#{policy.class} expected to forbid #{actions}, but
|
273
|
-
|
274
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
275
|
-
.inspect + '.'
|
259
|
+
"#{policy.class} expected to forbid #{actions}, but permitted " \
|
260
|
+
"#{forbidden_actions} for " \
|
261
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
276
262
|
end
|
277
263
|
end
|
278
264
|
end
|
@@ -283,15 +269,13 @@ module Pundit
|
|
283
269
|
end
|
284
270
|
|
285
271
|
failure_message do |policy|
|
286
|
-
"#{policy.class} does not permit the edit or update action for "
|
287
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
288
|
-
.inspect + '.'
|
272
|
+
"#{policy.class} does not permit the edit or update action for " \
|
273
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
289
274
|
end
|
290
275
|
|
291
276
|
failure_message_when_negated do |policy|
|
292
|
-
"#{policy.class} does not forbid the edit or update action for "
|
293
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
294
|
-
.inspect + '.'
|
277
|
+
"#{policy.class} does not forbid the edit or update action for " \
|
278
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
295
279
|
end
|
296
280
|
end
|
297
281
|
|
@@ -327,17 +311,15 @@ module Pundit
|
|
327
311
|
zero_attributes_failure_message
|
328
312
|
elsif defined? @action
|
329
313
|
"#{policy.class} expected to permit the mass assignment of the " \
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
334
|
-
.inspect + '.'
|
314
|
+
"attributes #{attributes} when authorising the #{@action} action, " \
|
315
|
+
'but forbade the mass assignment of the attributes ' \
|
316
|
+
"#{forbidden_attributes} for " \
|
317
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
335
318
|
else
|
336
319
|
"#{policy.class} expected to permit the mass assignment of the " \
|
337
|
-
|
338
|
-
|
339
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
340
|
-
.inspect + '.'
|
320
|
+
"attributes #{attributes}, but forbade the mass assignment of the " \
|
321
|
+
"attributes #{forbidden_attributes} for " \
|
322
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
341
323
|
end
|
342
324
|
end
|
343
325
|
|
@@ -346,17 +328,15 @@ module Pundit
|
|
346
328
|
zero_attributes_failure_message
|
347
329
|
elsif defined? @action
|
348
330
|
"#{policy.class} expected to forbid the mass assignment of the " \
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
353
|
-
.inspect + '.'
|
331
|
+
"attributes #{attributes} when authorising the #{@action} action, " \
|
332
|
+
'but forbade the mass assignment of the attributes ' \
|
333
|
+
"#{forbidden_attributes} for " \
|
334
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
354
335
|
else
|
355
336
|
"#{policy.class} expected to forbid the mass assignment of the " \
|
356
|
-
|
357
|
-
|
358
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
359
|
-
.inspect + '.'
|
337
|
+
"attributes #{attributes}, but forbade the mass assignment of the " \
|
338
|
+
"attributes #{forbidden_attributes} for " \
|
339
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
360
340
|
end
|
361
341
|
end
|
362
342
|
end
|
@@ -367,15 +347,13 @@ module Pundit
|
|
367
347
|
end
|
368
348
|
|
369
349
|
failure_message do |policy|
|
370
|
-
"#{policy.class} does not permit the new or create action for "
|
371
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
372
|
-
.inspect + '.'
|
350
|
+
"#{policy.class} does not permit the new or create action for " \
|
351
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
373
352
|
end
|
374
353
|
|
375
354
|
failure_message_when_negated do |policy|
|
376
|
-
"#{policy.class} does not forbid the new or create action for "
|
377
|
-
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
378
|
-
.inspect + '.'
|
355
|
+
"#{policy.class} does not forbid the new or create action for " \
|
356
|
+
"#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
|
379
357
|
end
|
380
358
|
end
|
381
359
|
|
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: 2.
|
4
|
+
version: 2.2.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: 2023-
|
11
|
+
date: 2023-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|
@@ -64,7 +64,7 @@ files:
|
|
64
64
|
- lib/pundit/matchers/utils/only_actions/permitted_actions_error_formatter.rb
|
65
65
|
- lib/pundit/matchers/utils/only_actions/permitted_actions_matcher.rb
|
66
66
|
- lib/pundit/matchers/utils/policy_info.rb
|
67
|
-
homepage:
|
67
|
+
homepage: https://github.com/punditcommunity/pundit-matchers
|
68
68
|
licenses:
|
69
69
|
- MIT
|
70
70
|
metadata:
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.4.12
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: RSpec matchers for Pundit policies
|