pundit-matchers 3.0.0.beta2 → 3.0.0.beta4

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: 77d8ee41dcadde3c30566854aa0ff3233a1d3d5a4af3cd6473da6b9b5853b808
4
- data.tar.gz: 7aa577655d4b28dcfe2d01b08dd9403034c0f968aae28f31d79ce29ef45688e9
3
+ metadata.gz: 9174f14f9868c035a2bfe235f28cac3565c22b11a0c13f3a4a7d35716a23ca16
4
+ data.tar.gz: f2dcbb7dc17617644f238ac24b4a558b32f4655936db2ba23bde8bbbf5df2c15
5
5
  SHA512:
6
- metadata.gz: 7f61f515a62d8ca955143480936812c3ec0a6f53779da950bf4b443ee837e5f3bad1cd6f8a6be630049a00a6e394ce2221cf581558c880712c64d1dc4aabf3ee
7
- data.tar.gz: afe2ef3fb5556f929f71ff53c7d8d821d6025d6b96b2370655ae9d0d0b225dc6cde66a28e4c04df27af2b5aacdb28cde554186fbe77f13f0a46b5cd922e1302b
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
@@ -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,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pundit-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta2
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-05-26 00:00:00.000000000 Z
11
+ date: 2023-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
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
26
  version: '3.12'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec-expectations
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3.12'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.12'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec-mocks
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.12'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.12'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-support
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.12'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.12'
69
69
  description: A set of RSpec matchers for testing Pundit authorisation policies