pundit-matchers 3.0.0.beta3 → 3.0.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/actions_matcher.rb +13 -0
- data/lib/pundit/matchers.rb +6 -6
- 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: 173bd01350678f5f224a05f59eb850422c8bdd722047fb734d5e78fb909a3a68
|
4
|
+
data.tar.gz: 26526d635f6ce6bfeb1eb57bc9f6912d7122795024d252b342655bdc4b133775
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06125a73c0018ada58310e1676c7188d5a450775aaf2018d1a384e71482d640d17b74fca56b057183d0b80ff83049e3d8324c5dc22f179430334b9af84e51e39
|
7
|
+
data.tar.gz: af7a4d988514fb990f9012a415eacd0fe947745b72c3ce97d2d155f8523a4631a07ef76e6ae13ee01690a7318fb573ba1130378b8b62a149900c681bd0c19026
|
@@ -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
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|
@@ -99,9 +99,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '3.0'
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - "
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
104
|
+
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubygems_version: 3.4.12
|
107
107
|
signing_key:
|