lib/pundit/matchers/actions_matcher.rb in pundit-matchers-3.0.0.beta3 vs lib/pundit/matchers/actions_matcher.rb in pundit-matchers-3.0.0.beta4
- old
+ new
@@ -8,10 +8,12 @@
class ActionsMatcher < BaseMatcher
# Error message when actions are not implemented in a policy.
ACTIONS_NOT_IMPLEMENTED_ERROR = "'%<policy>s' does not implement %<actions>s"
# Error message when at least one action must be specified.
ARGUMENTS_REQUIRED_ERROR = 'At least one action must be specified'
+ # Error message when only one action may be specified.
+ ONE_ARGUMENT_REQUIRED_ERROR = 'Only one action may be specified'
# Initializes a new instance of the ActionsMatcher class.
#
# @param expected_actions [Array<String, Symbol>] The expected actions to be checked.
#
@@ -19,9 +21,20 @@
def initialize(*expected_actions)
raise ArgumentError, ARGUMENTS_REQUIRED_ERROR if expected_actions.empty?
super()
@expected_actions = expected_actions.flatten.map(&:to_sym).sort
+ end
+
+ # Ensures that only one action is specified.
+ #
+ # @raise [ArgumentError] If more than one action is specified.
+ #
+ # @return [ActionsMatcher] The object itself.
+ def ensure_single_action!
+ raise ArgumentError, ONE_ARGUMENT_REQUIRED_ERROR if expected_actions.size > 1
+
+ self
end
private
attr_reader :expected_actions