pundit-matchers 2.3.0 → 3.0.0.beta1

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.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pundit/matchers/actions_matcher.rb +41 -0
  3. data/lib/pundit/matchers/attributes_matcher.rb +71 -0
  4. data/lib/pundit/matchers/base_matcher.rb +27 -0
  5. data/lib/pundit/matchers/forbid_all_actions_matcher.rb +43 -0
  6. data/lib/pundit/matchers/forbid_only_actions_matcher.rb +60 -0
  7. data/lib/pundit/matchers/permit_actions_matcher.rb +69 -0
  8. data/lib/pundit/matchers/permit_all_actions_matcher.rb +43 -0
  9. data/lib/pundit/matchers/permit_attributes_matcher.rb +65 -0
  10. data/lib/pundit/matchers/permit_only_actions_matcher.rb +60 -0
  11. data/lib/pundit/matchers/utils/policy_info.rb +67 -6
  12. data/lib/pundit/matchers.rb +120 -364
  13. metadata +16 -39
  14. data/lib/pundit/matchers/utils/all_actions/actions_matcher.rb +0 -39
  15. data/lib/pundit/matchers/utils/all_actions/error_message_formatter.rb +0 -47
  16. data/lib/pundit/matchers/utils/all_actions/forbidden_actions_error_formatter.rb +0 -26
  17. data/lib/pundit/matchers/utils/all_actions/forbidden_actions_matcher.rb +0 -20
  18. data/lib/pundit/matchers/utils/all_actions/permitted_actions_error_formatter.rb +0 -26
  19. data/lib/pundit/matchers/utils/all_actions/permitted_actions_matcher.rb +0 -20
  20. data/lib/pundit/matchers/utils/only_actions/actions_matcher.rb +0 -39
  21. data/lib/pundit/matchers/utils/only_actions/error_message_formatter.rb +0 -54
  22. data/lib/pundit/matchers/utils/only_actions/forbidden_actions_error_formatter.rb +0 -26
  23. data/lib/pundit/matchers/utils/only_actions/forbidden_actions_matcher.rb +0 -20
  24. data/lib/pundit/matchers/utils/only_actions/permitted_actions_error_formatter.rb +0 -26
  25. data/lib/pundit/matchers/utils/only_actions/permitted_actions_matcher.rb +0 -20
@@ -2,412 +2,168 @@
2
2
 
3
3
  require 'rspec/core'
4
4
 
5
+ require_relative 'matchers/permit_actions_matcher'
6
+
7
+ require_relative 'matchers/permit_attributes_matcher'
8
+
9
+ require_relative 'matchers/forbid_all_actions_matcher'
10
+ require_relative 'matchers/forbid_only_actions_matcher'
11
+
12
+ require_relative 'matchers/permit_all_actions_matcher'
13
+ require_relative 'matchers/permit_only_actions_matcher'
14
+
5
15
  module Pundit
16
+ # Matchers module provides a set of RSpec matchers for testing Pundit policies.
6
17
  module Matchers
7
- require_relative 'matchers/utils/policy_info'
8
- require_relative 'matchers/utils/all_actions/forbidden_actions_error_formatter'
9
- require_relative 'matchers/utils/all_actions/forbidden_actions_matcher'
10
- require_relative 'matchers/utils/all_actions/permitted_actions_error_formatter'
11
- require_relative 'matchers/utils/all_actions/permitted_actions_matcher'
12
-
13
- require_relative 'matchers/utils/only_actions/forbidden_actions_error_formatter'
14
- require_relative 'matchers/utils/only_actions/forbidden_actions_matcher'
15
- require_relative 'matchers/utils/only_actions/permitted_actions_error_formatter'
16
- require_relative 'matchers/utils/only_actions/permitted_actions_matcher'
18
+ # A Proc that negates the description of a matcher.
19
+ NEGATED_DESCRIPTION = ->(description) { description.gsub(/^permit/, 'forbid') }
17
20
 
21
+ # Configuration class for Pundit Matchers.
18
22
  class Configuration
19
- attr_accessor :user_alias
23
+ # The default user object value
24
+ DEFAULT_USER_ALIAS = :user
25
+
26
+ # The default user object in policies.
27
+ # @return [Symbol|String]
28
+ attr_accessor :default_user_alias
29
+
30
+ # Policy-specific user objects.
31
+ #
32
+ # @example Use +:client+ as user alias for class +Post+
33
+ # config.user_aliases = { 'Post' => :client }
34
+ #
35
+ # @return [Hash]
36
+ attr_accessor :user_aliases
20
37
 
21
38
  def initialize
22
- @user_alias = :user
39
+ @default_user_alias = DEFAULT_USER_ALIAS
40
+ @user_aliases = {}
41
+ end
42
+
43
+ # Returns the user object for the given policy.
44
+ #
45
+ # @return [Symbol]
46
+ def user_alias(policy)
47
+ user_aliases.fetch(policy.class.name, default_user_alias)
23
48
  end
24
49
  end
25
50
 
26
51
  class << self
52
+ # Configures Pundit Matchers.
53
+ #
54
+ # @yieldparam [Configuration] configuration the configuration object to be modified.
27
55
  def configure
28
56
  yield(configuration)
29
57
  end
30
58
 
59
+ # Returns the configuration object for Pundit Matchers.
60
+ #
61
+ # @return [Configuration] the configuration object.
31
62
  def configuration
32
63
  @configuration ||= Pundit::Matchers::Configuration.new
33
64
  end
34
65
  end
35
- end
36
-
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)
43
- end
44
- end
45
-
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
50
-
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
- end
55
- end
56
-
57
- RSpec::Matchers.define :forbid_actions do |*actions|
58
- actions.flatten!
59
- match do |policy|
60
- return false if actions.count < 1
61
-
62
- @allowed_actions = actions.select do |action|
63
- policy.public_send("#{action}?")
64
- end
65
- @allowed_actions.empty?
66
- end
67
-
68
- attr_reader :allowed_actions
69
-
70
- zero_actions_failure_message = 'At least one action must be ' \
71
- 'specified when using the forbid_actions matcher.'
72
-
73
- failure_message do |policy|
74
- if actions.count.zero?
75
- zero_actions_failure_message
76
- else
77
- "#{policy.class} expected to forbid #{actions}, but permitted " \
78
- "#{allowed_actions} for " \
79
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
80
- end
81
- end
82
-
83
- failure_message_when_negated do |policy|
84
- if actions.count.zero?
85
- zero_actions_failure_message
86
- else
87
- "#{policy.class} expected to permit #{actions}, but forbade " \
88
- "#{allowed_actions} for " \
89
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
90
- end
91
- end
92
- end
93
-
94
- RSpec::Matchers.define :forbid_edit_and_update_actions do
95
- match do |policy|
96
- !policy.edit? && !policy.update?
97
- end
98
-
99
- failure_message do |policy|
100
- "#{policy.class} does not forbid the edit or update action for " \
101
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
102
- end
103
-
104
- failure_message_when_negated do |policy|
105
- "#{policy.class} does not permit the edit or update action for " \
106
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
107
- end
108
- end
109
-
110
- RSpec::Matchers.define :forbid_mass_assignment_of do |attributes|
111
- # Map single object argument to an array, if necessary
112
- attributes = [attributes] unless attributes.is_a?(Array)
113
-
114
- match do |policy|
115
- return false if attributes.count < 1
116
-
117
- @allowed_attributes = attributes.select do |attribute|
118
- if defined? @action
119
- policy.send("permitted_attributes_for_#{@action}").include? attribute
120
- else
121
- policy.permitted_attributes.include? attribute
122
- end
123
- end
124
-
125
- @allowed_attributes.empty?
126
- end
127
-
128
- attr_reader :allowed_attributes
129
-
130
- chain :for_action do |action|
131
- @action = action
132
- end
133
-
134
- zero_attributes_failure_message = 'At least one attribute must be ' \
135
- 'specified when using the forbid_mass_assignment_of matcher.'
136
-
137
- failure_message do |policy|
138
- if attributes.count.zero?
139
- zero_attributes_failure_message
140
- elsif defined? @action
141
- "#{policy.class} expected to forbid the mass assignment of the " \
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}."
146
- else
147
- "#{policy.class} expected to forbid the mass assignment of the " \
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}."
151
- end
152
- end
153
-
154
- failure_message_when_negated do |policy|
155
- if attributes.count.zero?
156
- zero_attributes_failure_message
157
- elsif defined? @action
158
- "#{policy.class} expected to permit the mass assignment of the " \
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}."
163
- else
164
- "#{policy.class} expected to permit the mass assignment of the " \
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}."
168
- end
169
- end
170
- end
171
-
172
- RSpec::Matchers.define :forbid_new_and_create_actions do
173
- match do |policy|
174
- !policy.new? && !policy.create?
175
- end
176
-
177
- failure_message do |policy|
178
- "#{policy.class} does not forbid the new or create action for " \
179
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
180
- end
181
-
182
- failure_message_when_negated do |policy|
183
- "#{policy.class} does not permit the new or create action for " \
184
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
185
- end
186
- end
187
-
188
- RSpec::Matchers.define :permit_action do |action, *args, **kwargs|
189
- match do |policy|
190
- if args.any?
191
- policy.public_send("#{action}?", *args, **kwargs)
192
- else
193
- policy.public_send("#{action}?", **kwargs)
194
- end
195
- end
196
-
197
- failure_message do |policy|
198
- "#{policy.class} does not permit #{action} for " \
199
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
200
- end
201
66
 
202
- failure_message_when_negated do |policy|
203
- "#{policy.class} does not forbid #{action} for " \
204
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
67
+ # Creates a matcher that tests if the policy permits a given action.
68
+ #
69
+ # @param [Symbol] action the action to be tested.
70
+ # @return [PermitActionsMatcher] the matcher object.
71
+ def permit_action(action)
72
+ PermitActionsMatcher.new(action)
205
73
  end
206
- end
207
-
208
- RSpec::Matchers.define :permit_actions do |*actions|
209
- actions.flatten!
210
- match do |policy|
211
- return false if actions.count < 1
212
-
213
- @forbidden_actions = actions.reject do |action|
214
- policy.public_send("#{action}?")
215
- end
216
- @forbidden_actions.empty?
217
- end
218
-
219
- match_when_negated do |policy|
220
- ::Kernel.warn 'Using expect { }.not_to permit_actions could produce \
221
- confusing results. Please use `.to forbid_actions` instead. To \
222
- clarify, `.not_to permit_actions` will look at all of the actions and \
223
- checks if ANY actions fail, not if all actions fail. Therefore, you \
224
- could result in something like this: \
225
-
226
- it { is_expected.to permit_actions([:new, :create, :edit]) } \
227
- it { is_expected.not_to permit_actions([:edit, :destroy]) } \
228
74
 
229
- In this case, edit would be true and destroy would be false, but both \
230
- tests would pass.'
75
+ # @!macro [attach] RSpec::Matchers.define_negated_matcher
76
+ # @!method $1
77
+ #
78
+ # The negated matcher of {$2}.
79
+ #
80
+ # Same as +expect(policy).not_to $2(*args)+.
81
+ RSpec::Matchers.define_negated_matcher :forbid_action, :permit_action, &NEGATED_DESCRIPTION
231
82
 
232
- return true if actions.count < 1
233
-
234
- @forbidden_actions = actions.reject do |action|
235
- policy.public_send("#{action}?")
236
- end
237
- !@forbidden_actions.empty?
83
+ # Creates a matcher that tests if the policy permits a set of actions.
84
+ #
85
+ # @param [Array<Symbol>] actions the actions to be tested.
86
+ # @return [PermitActionsMatcher] the matcher object.
87
+ def permit_actions(*actions)
88
+ PermitActionsMatcher.new(*actions)
238
89
  end
239
90
 
240
- attr_reader :forbidden_actions
91
+ RSpec::Matchers.define_negated_matcher :forbid_actions, :permit_actions, &NEGATED_DESCRIPTION
241
92
 
242
- zero_actions_failure_message = 'At least one action must be specified ' \
243
- 'when using the permit_actions matcher.'
244
-
245
- failure_message do |policy|
246
- if actions.count.zero?
247
- zero_actions_failure_message
248
- else
249
- "#{policy.class} expected to permit #{actions}, but forbade " \
250
- "#{forbidden_actions} for " \
251
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
252
- end
93
+ # Creates a matcher that tests if the policy permits all actions.
94
+ #
95
+ # @note The negative form +not_to permit_all_actions+ is not supported
96
+ # since it creates ambiguity. Instead use +to forbid_all_actions+.
97
+ #
98
+ # @return [PermitAllActionsMatcher] the matcher object.
99
+ def permit_all_actions
100
+ PermitAllActionsMatcher.new
253
101
  end
254
102
 
255
- failure_message_when_negated do |policy|
256
- if actions.count.zero?
257
- zero_actions_failure_message
258
- else
259
- "#{policy.class} expected to forbid #{actions}, but permitted " \
260
- "#{forbidden_actions} for " \
261
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
262
- end
103
+ # Creates a matcher that tests if the policy forbids all actions.
104
+ #
105
+ # @note The negative form +not_to forbid_all_actions+ is not supported
106
+ # since it creates ambiguity. Instead use +to permit_all_actions+.
107
+ #
108
+ # @return [ForbidAllActionsMatcher] the matcher object.
109
+ def forbid_all_actions
110
+ ForbidAllActionsMatcher.new
263
111
  end
264
- end
265
112
 
266
- RSpec::Matchers.define :permit_edit_and_update_actions do
267
- match do |policy|
268
- policy.edit? && policy.update?
113
+ # Creates a matcher that tests if the policy permits the edit and update actions.
114
+ #
115
+ # @return [PermitActionsMatcher] the matcher object.
116
+ def permit_edit_and_update_actions
117
+ PermitActionsMatcher.new(:edit, :update)
269
118
  end
270
119
 
271
- failure_message do |policy|
272
- "#{policy.class} does not permit the edit or update action for " \
273
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
274
- end
120
+ RSpec::Matchers.define_negated_matcher :forbid_edit_and_update_actions, :permit_edit_and_update_actions,
121
+ &NEGATED_DESCRIPTION
275
122
 
276
- failure_message_when_negated do |policy|
277
- "#{policy.class} does not forbid the edit or update action for " \
278
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
123
+ # Creates a matcher that tests if the policy permits the new and create actions.
124
+ #
125
+ # @return [PermitActionsMatcher] the matcher object.
126
+ def permit_new_and_create_actions
127
+ PermitActionsMatcher.new(:new, :create)
279
128
  end
280
- end
281
129
 
282
- RSpec::Matchers.define :permit_mass_assignment_of do |attributes|
283
- # Map single object argument to an array, if necessary
284
- attributes = [attributes] unless attributes.is_a?(Array)
130
+ RSpec::Matchers.define_negated_matcher :forbid_new_and_create_actions, :permit_new_and_create_actions,
131
+ &NEGATED_DESCRIPTION
285
132
 
286
- match do |policy|
287
- return false if attributes.count < 1
288
-
289
- @forbidden_attributes = attributes.select do |attribute|
290
- if defined? @action
291
- !policy.send("permitted_attributes_for_#{@action}").include? attribute
292
- else
293
- !policy.permitted_attributes.include? attribute
294
- end
295
- end
296
-
297
- @forbidden_attributes.empty?
133
+ # Creates a matcher that tests if the policy permits only a set of actions.
134
+ #
135
+ # @note The negative form +not_to permit_only_actions+ is not supported
136
+ # since it creates ambiguity. Instead use +to forbid_only_actions+.
137
+ #
138
+ # @param [Array<Symbol>] actions the actions to be tested.
139
+ # @return [PermitOnlyActionsMatcher] the matcher object.
140
+ def permit_only_actions(*actions)
141
+ PermitOnlyActionsMatcher.new(*actions)
298
142
  end
299
143
 
300
- attr_reader :forbidden_attributes
301
-
302
- chain :for_action do |action|
303
- @action = action
144
+ # Creates a matcher that tests if the policy forbids only a set of actions.
145
+ #
146
+ # @note The negative form +not_to forbid_only_actions+ is not supported
147
+ # since it creates ambiguity. Instead use +to permit_only_actions+.
148
+ #
149
+ # @param [Array<Symbol>] actions the actions to be tested.
150
+ # @return [ForbidOnlyActionsMatcher] the matcher object.
151
+ def forbid_only_actions(*actions)
152
+ ForbidOnlyActionsMatcher.new(*actions)
304
153
  end
305
154
 
306
- zero_attributes_failure_message = 'At least one attribute must be ' \
307
- 'specified when using the permit_mass_assignment_of matcher.'
308
-
309
- failure_message do |policy|
310
- if attributes.count.zero?
311
- zero_attributes_failure_message
312
- elsif defined? @action
313
- "#{policy.class} expected to permit the mass assignment of the " \
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}."
318
- else
319
- "#{policy.class} expected to permit the mass assignment of the " \
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}."
323
- end
155
+ # Creates a matcher that tests if the policy permits mass assignment of a set of attributes.
156
+ #
157
+ # @param [Array<Symbol>] attributes the attributes to be tested.
158
+ # @return [PermitAttributesMatcher] the matcher object.
159
+ def permit_mass_assignment_of(*attributes)
160
+ PermitAttributesMatcher.new(*attributes)
324
161
  end
325
162
 
326
- failure_message_when_negated do |policy|
327
- if attributes.count.zero?
328
- zero_attributes_failure_message
329
- elsif defined? @action
330
- "#{policy.class} expected to forbid the mass assignment of the " \
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}."
335
- else
336
- "#{policy.class} expected to forbid the mass assignment of the " \
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}."
340
- end
341
- end
342
- end
343
-
344
- RSpec::Matchers.define :permit_new_and_create_actions do
345
- match do |policy|
346
- policy.new? && policy.create?
347
- end
348
-
349
- failure_message do |policy|
350
- "#{policy.class} does not permit the new or create action for " \
351
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
352
- end
353
-
354
- failure_message_when_negated do |policy|
355
- "#{policy.class} does not forbid the new or create action for " \
356
- "#{policy.public_send(Pundit::Matchers.configuration.user_alias).inspect}."
357
- end
358
- end
359
-
360
- RSpec::Matchers.define :permit_all_actions do
361
- match do |policy|
362
- @matcher = Pundit::Matchers::Utils::AllActions::PermittedActionsMatcher.new(policy)
363
- @matcher.match?
364
- end
365
-
366
- failure_message do
367
- formatter = Pundit::Matchers::Utils::AllActions::PermittedActionsErrorFormatter.new(@matcher)
368
- formatter.message
369
- end
370
- end
371
-
372
- RSpec::Matchers.define :permit_only_actions do |actions|
373
- match do |policy|
374
- @matcher = Pundit::Matchers::Utils::OnlyActions::PermittedActionsMatcher.new(policy, actions)
375
- @matcher.match?
376
- end
377
-
378
- failure_message do
379
- formatter = Pundit::Matchers::Utils::OnlyActions::PermittedActionsErrorFormatter.new(@matcher)
380
- formatter.message
381
- end
382
- end
383
-
384
- RSpec::Matchers.define :forbid_all_actions do
385
- match do |policy|
386
- @matcher = Pundit::Matchers::Utils::AllActions::ForbiddenActionsMatcher.new(policy)
387
- @matcher.match?
388
- end
389
-
390
- failure_message do
391
- formatter = Pundit::Matchers::Utils::AllActions::ForbiddenActionsErrorFormatter.new(@matcher)
392
- formatter.message
393
- end
394
- end
395
-
396
- RSpec::Matchers.define :forbid_only_actions do |actions|
397
- match do |policy|
398
- @matcher = Pundit::Matchers::Utils::OnlyActions::ForbiddenActionsMatcher.new(policy, actions)
399
- @matcher.match?
400
- end
401
-
402
- failure_message do
403
- formatter = Pundit::Matchers::Utils::OnlyActions::ForbiddenActionsErrorFormatter.new(@matcher)
404
- formatter.message
405
- end
163
+ RSpec::Matchers.define_negated_matcher :forbid_mass_assignment_of, :permit_mass_assignment_of, &NEGATED_DESCRIPTION
406
164
  end
407
165
  end
408
166
 
409
- if defined?(Pundit)
410
- RSpec.configure do |config|
411
- config.include Pundit::Matchers
412
- end
167
+ RSpec.configure do |config|
168
+ config.include Pundit::Matchers
413
169
  end
metadata CHANGED
@@ -1,49 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pundit-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 3.0.0.beta1
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-05-23 00:00:00.000000000 Z
11
+ date: 2023-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec-rails
14
+ name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0
19
+ version: '3.12'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.0
27
- - !ruby/object:Gem::Dependency
28
- name: pundit
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.1'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 1.1.0
37
- type: :development
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '1.1'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 1.1.0
26
+ version: '3.12'
47
27
  description: A set of RSpec matchers for testing Pundit authorisation policies
48
28
  email: chris@chrisalley.info
49
29
  executables: []
@@ -51,18 +31,15 @@ extensions: []
51
31
  extra_rdoc_files: []
52
32
  files:
53
33
  - lib/pundit/matchers.rb
54
- - lib/pundit/matchers/utils/all_actions/actions_matcher.rb
55
- - lib/pundit/matchers/utils/all_actions/error_message_formatter.rb
56
- - lib/pundit/matchers/utils/all_actions/forbidden_actions_error_formatter.rb
57
- - lib/pundit/matchers/utils/all_actions/forbidden_actions_matcher.rb
58
- - lib/pundit/matchers/utils/all_actions/permitted_actions_error_formatter.rb
59
- - lib/pundit/matchers/utils/all_actions/permitted_actions_matcher.rb
60
- - lib/pundit/matchers/utils/only_actions/actions_matcher.rb
61
- - lib/pundit/matchers/utils/only_actions/error_message_formatter.rb
62
- - lib/pundit/matchers/utils/only_actions/forbidden_actions_error_formatter.rb
63
- - lib/pundit/matchers/utils/only_actions/forbidden_actions_matcher.rb
64
- - lib/pundit/matchers/utils/only_actions/permitted_actions_error_formatter.rb
65
- - lib/pundit/matchers/utils/only_actions/permitted_actions_matcher.rb
34
+ - lib/pundit/matchers/actions_matcher.rb
35
+ - lib/pundit/matchers/attributes_matcher.rb
36
+ - lib/pundit/matchers/base_matcher.rb
37
+ - lib/pundit/matchers/forbid_all_actions_matcher.rb
38
+ - lib/pundit/matchers/forbid_only_actions_matcher.rb
39
+ - lib/pundit/matchers/permit_actions_matcher.rb
40
+ - lib/pundit/matchers/permit_all_actions_matcher.rb
41
+ - lib/pundit/matchers/permit_attributes_matcher.rb
42
+ - lib/pundit/matchers/permit_only_actions_matcher.rb
66
43
  - lib/pundit/matchers/utils/policy_info.rb
67
44
  homepage: https://github.com/punditcommunity/pundit-matchers
68
45
  licenses:
@@ -80,9 +57,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
57
  version: '3.0'
81
58
  required_rubygems_version: !ruby/object:Gem::Requirement
82
59
  requirements:
83
- - - ">="
60
+ - - ">"
84
61
  - !ruby/object:Gem::Version
85
- version: '0'
62
+ version: 1.3.1
86
63
  requirements: []
87
64
  rubygems_version: 3.4.12
88
65
  signing_key:
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pundit
4
- module Matchers
5
- module Utils
6
- module AllActions
7
- # Parent class for specific all_action matcher. Should not be used directly.
8
- #
9
- # Expects methods in child class:
10
- # * actual_actions - list of actions which actually matches expected type.
11
- class ActionsMatcher
12
- attr_reader :policy_info
13
-
14
- def initialize(policy)
15
- @policy_info = PolicyInfo.new(policy)
16
- end
17
-
18
- def match?
19
- missed_expected_actions.empty?
20
- end
21
-
22
- def missed_expected_actions
23
- @missed_expected_actions ||= expected_actions - actual_actions
24
- end
25
-
26
- def policy
27
- policy_info.policy
28
- end
29
-
30
- private
31
-
32
- def expected_actions
33
- policy_info.actions
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end