pundit-matchers 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 173bd01350678f5f224a05f59eb850422c8bdd722047fb734d5e78fb909a3a68
4
- data.tar.gz: 26526d635f6ce6bfeb1eb57bc9f6912d7122795024d252b342655bdc4b133775
3
+ metadata.gz: 379030415885d5cd2557f7540639e6c835f53cfa5a88895fd3e5f7cbbdf1b88f
4
+ data.tar.gz: 5a5e5f7586d31f4328e3e0b5bf722d3465a681ef77340a90d44b6517f04eb700
5
5
  SHA512:
6
- metadata.gz: 06125a73c0018ada58310e1676c7188d5a450775aaf2018d1a384e71482d640d17b74fca56b057183d0b80ff83049e3d8324c5dc22f179430334b9af84e51e39
7
- data.tar.gz: af7a4d988514fb990f9012a415eacd0fe947745b72c3ce97d2d155f8523a4631a07ef76e6ae13ee01690a7318fb573ba1130378b8b62a149900c681bd0c19026
6
+ metadata.gz: 5c513efb4f063cd3bd15d43c0a68d001bb4ca4ef806861b27cc0de39f7102d6aab8be0ee2b64213b83f8991d38d9e3f62ae6f7b0c03f0ae87f2f1f71fba87b0c
7
+ data.tar.gz: a32970e872d608219955154cdd43812b36a4d0d37363e09d0e17e341f297c23afb0e947756711b1df3d1c0aad3bcc48a43935663072b87656f196bfdb049afab
@@ -41,7 +41,8 @@ module Pundit
41
41
  attr_reader :expected_actions
42
42
 
43
43
  def check_actions!
44
- missing_actions = expected_actions - policy_info.actions
44
+ non_explicit_actions = (expected_actions - policy_info.actions)
45
+ missing_actions = non_explicit_actions.reject { |action| policy_info.policy.respond_to?(:"#{action}?") }
45
46
  return if missing_actions.empty?
46
47
 
47
48
  raise ArgumentError, format(
@@ -8,6 +8,8 @@ module Pundit
8
8
  class AttributesMatcher < BaseMatcher
9
9
  # Error message to be raised when no attributes are specified.
10
10
  ARGUMENTS_REQUIRED_ERROR = 'At least one attribute must be specified'
11
+ # Error message to be raised when only one attribute may be specified.
12
+ ONE_ARGUMENT_REQUIRED_ERROR = 'Only one attribute may be specified'
11
13
 
12
14
  # Initializes a new instance of the AttributesMatcher class.
13
15
  #
@@ -29,6 +31,17 @@ module Pundit
29
31
  self
30
32
  end
31
33
 
34
+ # Ensures that only one attribute is specified.
35
+ #
36
+ # @raise [ArgumentError] If more than one attribute is specified.
37
+ #
38
+ # @return [AttributesMatcher] The object itself.
39
+ def ensure_single_attribute!
40
+ raise ArgumentError, ONE_ARGUMENT_REQUIRED_ERROR if expected_attributes.size > 1
41
+
42
+ self
43
+ end
44
+
32
45
  private
33
46
 
34
47
  attr_reader :expected_attributes, :options
@@ -152,15 +152,32 @@ module Pundit
152
152
  ForbidOnlyActionsMatcher.new(*actions)
153
153
  end
154
154
 
155
+ # Creates a matcher that tests if the policy permits mass assignment of an attribute.
156
+ #
157
+ # @param [String, Symbol, Hash] attribute the attribute to be tested.
158
+ # @return [PermitAttributesMatcher] the matcher object.
159
+ def permit_attribute(attribute)
160
+ PermitAttributesMatcher.new(attribute).ensure_single_attribute!
161
+ end
162
+
163
+ RSpec::Matchers.define_negated_matcher :forbid_attribute, :permit_attribute, &NEGATED_DESCRIPTION
164
+
155
165
  # Creates a matcher that tests if the policy permits mass assignment of a set of attributes.
156
166
  #
157
167
  # @param [Array<String, Symbol, Hash>] attributes the attributes to be tested.
158
168
  # @return [PermitAttributesMatcher] the matcher object.
159
- def permit_mass_assignment_of(*attributes)
169
+ def permit_attributes(*attributes)
160
170
  PermitAttributesMatcher.new(*attributes)
161
171
  end
162
172
 
163
- RSpec::Matchers.define_negated_matcher :forbid_mass_assignment_of, :permit_mass_assignment_of, &NEGATED_DESCRIPTION
173
+ RSpec::Matchers.define_negated_matcher :forbid_attributes, :permit_attributes, &NEGATED_DESCRIPTION
174
+
175
+ # @!macro [attach] RSpec::Matchers.alias_matcher
176
+ # @!method $1
177
+ #
178
+ # An alias matcher for {$2}.
179
+ RSpec::Matchers.alias_matcher :permit_mass_assignment_of, :permit_attributes
180
+ RSpec::Matchers.alias_matcher :forbid_mass_assignment_of, :forbid_attributes
164
181
  end
165
182
  end
166
183
 
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.1.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-06-14 00:00:00.000000000 Z
11
+ date: 2023-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core