Sha256: fbdcc1ecd9aa846916c742eea7c126ad2617091bf26bcf1f849f023810f6a010

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require_relative 'base_matcher'

module Pundit
  module Matchers
    # This matcher tests whether a policy permits all actions.
    class PermitAllActionsMatcher < BaseMatcher
      # A description of the matcher.
      #
      # @return [String] A description of the matcher.
      def description
        'permit all actions'
      end

      # Checks if the given policy permits all actions.
      #
      # @param policy [Object] The policy to test.
      # @return [Boolean] True if the policy permits all actions, false otherwise.
      def matches?(policy)
        setup_policy_info! policy

        policy_info.forbidden_actions.empty?
      end

      # Raises a NotImplementedError
      # @raise NotImplementedError
      # @return [void]
      def does_not_match?(_policy)
        raise NotImplementedError, format(AMBIGUOUS_NEGATED_MATCHER_ERROR, name: 'permit_all_actions')
      end

      # Returns a failure message when the policy does not permit all actions.
      #
      # @return [String] A failure message when the policy does not permit all actions.
      def failure_message
        message = +"expected '#{policy_info}' to permit all actions,"
        message << " but forbade #{policy_info.forbidden_actions}"
        message << user_message
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pundit-matchers-3.1.2 lib/pundit/matchers/permit_all_actions_matcher.rb
pundit-matchers-3.1.1 lib/pundit/matchers/permit_all_actions_matcher.rb
pundit-matchers-3.1.0 lib/pundit/matchers/permit_all_actions_matcher.rb
pundit-matchers-3.0.1 lib/pundit/matchers/permit_all_actions_matcher.rb
pundit-matchers-3.0.0 lib/pundit/matchers/permit_all_actions_matcher.rb
pundit-matchers-3.0.0.beta4 lib/pundit/matchers/permit_all_actions_matcher.rb
pundit-matchers-3.0.0.beta3 lib/pundit/matchers/permit_all_actions_matcher.rb
pundit-matchers-3.0.0.beta2 lib/pundit/matchers/permit_all_actions_matcher.rb
pundit-matchers-3.0.0.beta1 lib/pundit/matchers/permit_all_actions_matcher.rb