pundit-matchers 1.6.0 → 1.8.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.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/pundit/matchers.rb +54 -2
  3. metadata +13 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ebd49115f1fcd116573587c08ba1e87701d69ab1
4
- data.tar.gz: 20875c30d34d115d91918ad6031bb3b7b5bf899e
2
+ SHA256:
3
+ metadata.gz: 5e756461a913daedaa92add1abd2adea7b443c3b464a69d9f886b0b42ee1d494
4
+ data.tar.gz: a2d43fab802f77cbce983be5428c179589cfcded1ee9f86f8b4e8a199b68653c
5
5
  SHA512:
6
- metadata.gz: c4634c52a265faacfcf42971b28994d585b1c33233f691c21a4499afa8d4ceb36170b2563702477d9caa1eff5560999c3ca05444f9db8496045d3b97981967c5
7
- data.tar.gz: f301a9c3f2cc38fcb4dc5c71f46ac07462ad0022c8b5bc5f7822687274b27204e7a66e22245aeb9e24a0ddb9c40e741ea0918131246f3f9888e616d42424f1b0
6
+ metadata.gz: 99c357cf6e1a3b3966a780ec8a8fbefb51949bda85fc2b512919f893c31b1a4b5c8a0cd8595209a8ebfb38e6f156ee52c1b5e51b6422a603337c5484a7356b20
7
+ data.tar.gz: 2595257307c5b56c8e13dba00956f2e2d51f62046c935bd7cda7e4194a25a2c2b8e9350e0b70a2d6967ea2afa06c79b1d096d970dcd27c903a0fcbbe5dfbc271
@@ -2,6 +2,12 @@ require 'rspec/core'
2
2
 
3
3
  module Pundit
4
4
  module Matchers
5
+ require 'pundit/matchers/utils/policy_info'
6
+ require 'pundit/matchers/utils/all_actions/forbidden_actions_error_formatter'
7
+ require 'pundit/matchers/utils/all_actions/forbidden_actions_matcher'
8
+ require 'pundit/matchers/utils/all_actions/permitted_actions_error_formatter'
9
+ require 'pundit/matchers/utils/all_actions/permitted_actions_matcher'
10
+
5
11
  class Configuration
6
12
  attr_accessor :user_alias
7
13
 
@@ -43,7 +49,8 @@ module Pundit
43
49
  end
44
50
  end
45
51
 
46
- RSpec::Matchers.define :forbid_actions do |actions|
52
+ RSpec::Matchers.define :forbid_actions do |*actions|
53
+ actions.flatten!
47
54
  match do |policy|
48
55
  return false if actions.count < 1
49
56
  @allowed_actions = actions.select do |action|
@@ -204,7 +211,8 @@ module Pundit
204
211
  end
205
212
  end
206
213
 
207
- RSpec::Matchers.define :permit_actions do |actions|
214
+ RSpec::Matchers.define :permit_actions do |*actions|
215
+ actions.flatten!
208
216
  match do |policy|
209
217
  return false if actions.count < 1
210
218
  @forbidden_actions = actions.reject do |action|
@@ -213,6 +221,26 @@ module Pundit
213
221
  @forbidden_actions.empty?
214
222
  end
215
223
 
224
+ match_when_negated do |policy|
225
+ ::Kernel.warn 'Using expect { }.not_to permit_actions could produce \
226
+ confusing results. Please use `.to forbid_actions` instead. To \
227
+ clarify, `.not_to permit_actions` will look at all of the actions and \
228
+ checks if ANY actions fail, not if all actions fail. Therefore, you \
229
+ could result in something like this: \
230
+
231
+ it { is_expected.to permit_actions([:new, :create, :edit]) } \
232
+ it { is_expected.not_to permit_actions([:edit, :destroy]) } \
233
+
234
+ In this case, edit would be true and destroy would be false, but both \
235
+ tests would pass.'
236
+
237
+ return true if actions.count < 1
238
+ @forbidden_actions = actions.reject do |action|
239
+ policy.public_send("#{action}?")
240
+ end
241
+ !@forbidden_actions.empty?
242
+ end
243
+
216
244
  attr_reader :forbidden_actions
217
245
 
218
246
  zero_actions_failure_message = 'At least one action must be specified ' \
@@ -342,6 +370,30 @@ module Pundit
342
370
  .inspect + '.'
343
371
  end
344
372
  end
373
+
374
+ RSpec::Matchers.define :permit_all_actions do
375
+ match do |policy|
376
+ @matcher = Pundit::Matchers::Utils::AllActions::PermittedActionsMatcher.new(policy)
377
+ @matcher.match?
378
+ end
379
+
380
+ failure_message do
381
+ formatter = Pundit::Matchers::Utils::AllActions::PermittedActionsErrorFormatter.new(@matcher)
382
+ formatter.message
383
+ end
384
+ end
385
+
386
+ RSpec::Matchers.define :forbid_all_actions do
387
+ match do |policy|
388
+ @matcher = Pundit::Matchers::Utils::AllActions::ForbiddenActionsMatcher.new(policy)
389
+ @matcher.match?
390
+ end
391
+
392
+ failure_message do
393
+ formatter = Pundit::Matchers::Utils::AllActions::ForbiddenActionsErrorFormatter.new(@matcher)
394
+ formatter.message
395
+ end
396
+ end
345
397
  end
346
398
 
347
399
  if defined?(Pundit)
metadata CHANGED
@@ -1,19 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pundit-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.8.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: 2018-05-26 00:00:00.000000000 Z
11
+ date: 2022-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
22
  version: 3.0.0
@@ -21,6 +24,9 @@ dependencies:
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
32
  version: 3.0.0
@@ -51,11 +57,11 @@ extensions: []
51
57
  extra_rdoc_files: []
52
58
  files:
53
59
  - lib/pundit/matchers.rb
54
- homepage: http://github.com/chrisalley/pundit-matchers
60
+ homepage: http://github.com/punditcommunity/pundit-matchers
55
61
  licenses:
56
62
  - MIT
57
63
  metadata: {}
58
- post_install_message:
64
+ post_install_message:
59
65
  rdoc_options: []
60
66
  require_paths:
61
67
  - lib
@@ -70,9 +76,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
76
  - !ruby/object:Gem::Version
71
77
  version: '0'
72
78
  requirements: []
73
- rubyforge_project:
74
- rubygems_version: 2.6.14
75
- signing_key:
79
+ rubygems_version: 3.3.7
80
+ signing_key:
76
81
  specification_version: 4
77
82
  summary: RSpec matchers for Pundit policies
78
83
  test_files: []