pundit-matchers 3.0.0.beta3 → 3.0.0.beta4
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/actions_matcher.rb +13 -0
- data/lib/pundit/matchers.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9174f14f9868c035a2bfe235f28cac3565c22b11a0c13f3a4a7d35716a23ca16
|
4
|
+
data.tar.gz: f2dcbb7dc17617644f238ac24b4a558b32f4655936db2ba23bde8bbbf5df2c15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8873422c0d9c94cf0955d0e088736a90597298a3e38030bbaf15cd73420c77a6e27a44c16dd001e36d63c77354dc76c711c0486c8133b2deb02cbeb5c59ed305
|
7
|
+
data.tar.gz: 3d20ac4a45dbdb83c1c7dd58a54aa8c869c3780c000f11ac5c46c8d8e075b855ac8172d0b9964279035699a48d885a0f85b2378492d196c2edc6cb11af8a198e
|
@@ -10,6 +10,8 @@ module Pundit
|
|
10
10
|
ACTIONS_NOT_IMPLEMENTED_ERROR = "'%<policy>s' does not implement %<actions>s"
|
11
11
|
# Error message when at least one action must be specified.
|
12
12
|
ARGUMENTS_REQUIRED_ERROR = 'At least one action must be specified'
|
13
|
+
# Error message when only one action may be specified.
|
14
|
+
ONE_ARGUMENT_REQUIRED_ERROR = 'Only one action may be specified'
|
13
15
|
|
14
16
|
# Initializes a new instance of the ActionsMatcher class.
|
15
17
|
#
|
@@ -23,6 +25,17 @@ module Pundit
|
|
23
25
|
@expected_actions = expected_actions.flatten.map(&:to_sym).sort
|
24
26
|
end
|
25
27
|
|
28
|
+
# Ensures that only one action is specified.
|
29
|
+
#
|
30
|
+
# @raise [ArgumentError] If more than one action is specified.
|
31
|
+
#
|
32
|
+
# @return [ActionsMatcher] The object itself.
|
33
|
+
def ensure_single_action!
|
34
|
+
raise ArgumentError, ONE_ARGUMENT_REQUIRED_ERROR if expected_actions.size > 1
|
35
|
+
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
26
39
|
private
|
27
40
|
|
28
41
|
attr_reader :expected_actions
|
data/lib/pundit/matchers.rb
CHANGED
@@ -66,10 +66,10 @@ module Pundit
|
|
66
66
|
|
67
67
|
# Creates a matcher that tests if the policy permits a given action.
|
68
68
|
#
|
69
|
-
# @param [Symbol] action the action to be tested.
|
69
|
+
# @param [String|Symbol] action the action to be tested.
|
70
70
|
# @return [PermitActionsMatcher] the matcher object.
|
71
71
|
def permit_action(action)
|
72
|
-
PermitActionsMatcher.new(action)
|
72
|
+
PermitActionsMatcher.new(action).ensure_single_action!
|
73
73
|
end
|
74
74
|
|
75
75
|
# @!macro [attach] RSpec::Matchers.define_negated_matcher
|
@@ -82,7 +82,7 @@ module Pundit
|
|
82
82
|
|
83
83
|
# Creates a matcher that tests if the policy permits a set of actions.
|
84
84
|
#
|
85
|
-
# @param [Array<Symbol>] actions the actions to be tested.
|
85
|
+
# @param [Array<String, Symbol>] actions the actions to be tested.
|
86
86
|
# @return [PermitActionsMatcher] the matcher object.
|
87
87
|
def permit_actions(*actions)
|
88
88
|
PermitActionsMatcher.new(*actions)
|
@@ -135,7 +135,7 @@ module Pundit
|
|
135
135
|
# @note The negative form +not_to permit_only_actions+ is not supported
|
136
136
|
# since it creates ambiguity. Instead use +to forbid_only_actions+.
|
137
137
|
#
|
138
|
-
# @param [Array<Symbol>] actions the actions to be tested.
|
138
|
+
# @param [Array<String, Symbol>] actions the actions to be tested.
|
139
139
|
# @return [PermitOnlyActionsMatcher] the matcher object.
|
140
140
|
def permit_only_actions(*actions)
|
141
141
|
PermitOnlyActionsMatcher.new(*actions)
|
@@ -146,7 +146,7 @@ module Pundit
|
|
146
146
|
# @note The negative form +not_to forbid_only_actions+ is not supported
|
147
147
|
# since it creates ambiguity. Instead use +to permit_only_actions+.
|
148
148
|
#
|
149
|
-
# @param [Array<Symbol>] actions the actions to be tested.
|
149
|
+
# @param [Array<String, Symbol>] actions the actions to be tested.
|
150
150
|
# @return [ForbidOnlyActionsMatcher] the matcher object.
|
151
151
|
def forbid_only_actions(*actions)
|
152
152
|
ForbidOnlyActionsMatcher.new(*actions)
|
@@ -154,7 +154,7 @@ module Pundit
|
|
154
154
|
|
155
155
|
# Creates a matcher that tests if the policy permits mass assignment of a set of attributes.
|
156
156
|
#
|
157
|
-
# @param [Array<Symbol>] attributes the attributes to be tested.
|
157
|
+
# @param [Array<String, Symbol, Hash>] attributes the attributes to be tested.
|
158
158
|
# @return [PermitAttributesMatcher] the matcher object.
|
159
159
|
def permit_mass_assignment_of(*attributes)
|
160
160
|
PermitAttributesMatcher.new(*attributes)
|
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: 3.0.0.
|
4
|
+
version: 3.0.0.beta4
|
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-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|