module Pundit::Matchers

Matchers module provides a set of RSpec matchers for testing Pundit policies.

Constants

NEGATED_DESCRIPTION

A Proc that negates the description of a matcher.

Public Class Methods

configuration() click to toggle source

Returns the configuration object for Pundit Matchers.

@return [Configuration] the configuration object.

# File lib/pundit/matchers.rb, line 62
def configuration
  @configuration ||= Pundit::Matchers::Configuration.new
end
configure() { |configuration| ... } click to toggle source

Configures Pundit Matchers.

@yieldparam [Configuration] configuration the configuration object to be modified.

# File lib/pundit/matchers.rb, line 55
def configure
  yield(configuration)
end

Public Instance Methods

forbid_all_actions() click to toggle source

Creates a matcher that tests if the policy forbids all actions.

@note The negative form +not_to forbid_all_actions+ is not supported

since it creates ambiguity. Instead use +to permit_all_actions+.

@return [ForbidAllActionsMatcher] the matcher object.

# File lib/pundit/matchers.rb, line 109
def forbid_all_actions
  ForbidAllActionsMatcher.new
end
forbid_only_actions(*actions) click to toggle source

Creates a matcher that tests if the policy forbids only a set of actions.

@note The negative form +not_to forbid_only_actions+ is not supported

since it creates ambiguity. Instead use +to permit_only_actions+.

@param [Array<String, Symbol>] actions the actions to be tested. @return [ForbidOnlyActionsMatcher] the matcher object.

# File lib/pundit/matchers.rb, line 151
def forbid_only_actions(*actions)
  ForbidOnlyActionsMatcher.new(*actions)
end
permit_action(action) click to toggle source

Creates a matcher that tests if the policy permits a given action.

@param [String|Symbol] action the action to be tested. @return [PermitActionsMatcher] the matcher object.

# File lib/pundit/matchers.rb, line 71
def permit_action(action)
  PermitActionsMatcher.new(action).ensure_single_action!
end
permit_actions(*actions) click to toggle source

Creates a matcher that tests if the policy permits a set of actions.

@param [Array<String, Symbol>] actions the actions to be tested. @return [PermitActionsMatcher] the matcher object.

# File lib/pundit/matchers.rb, line 87
def permit_actions(*actions)
  PermitActionsMatcher.new(*actions)
end
permit_all_actions() click to toggle source

Creates a matcher that tests if the policy permits all actions.

@note The negative form +not_to permit_all_actions+ is not supported

since it creates ambiguity. Instead use +to forbid_all_actions+.

@return [PermitAllActionsMatcher] the matcher object.

# File lib/pundit/matchers.rb, line 99
def permit_all_actions
  PermitAllActionsMatcher.new
end
permit_attribute(attribute) click to toggle source

Creates a matcher that tests if the policy permits mass assignment of an attribute.

@param [String, Symbol, Hash] attribute the attribute to be tested. @return [PermitAttributesMatcher] the matcher object.

# File lib/pundit/matchers.rb, line 159
def permit_attribute(attribute)
  PermitAttributesMatcher.new(attribute).ensure_single_attribute!
end
permit_attributes(*attributes) click to toggle source

Creates a matcher that tests if the policy permits mass assignment of a set of attributes.

@param [Array<String, Symbol, Hash>] attributes the attributes to be tested. @return [PermitAttributesMatcher] the matcher object.

# File lib/pundit/matchers.rb, line 169
def permit_attributes(*attributes)
  PermitAttributesMatcher.new(*attributes)
end
permit_edit_and_update_actions() click to toggle source

Creates a matcher that tests if the policy permits the edit and update actions.

@return [PermitActionsMatcher] the matcher object.

# File lib/pundit/matchers.rb, line 116
def permit_edit_and_update_actions
  PermitActionsMatcher.new(:edit, :update)
end
permit_new_and_create_actions() click to toggle source

Creates a matcher that tests if the policy permits the new and create actions.

@return [PermitActionsMatcher] the matcher object.

# File lib/pundit/matchers.rb, line 126
def permit_new_and_create_actions
  PermitActionsMatcher.new(:new, :create)
end
permit_only_actions(*actions) click to toggle source

Creates a matcher that tests if the policy permits only a set of actions.

@note The negative form +not_to permit_only_actions+ is not supported

since it creates ambiguity. Instead use +to forbid_only_actions+.

@param [Array<String, Symbol>] actions the actions to be tested. @return [PermitOnlyActionsMatcher] the matcher object.

# File lib/pundit/matchers.rb, line 140
def permit_only_actions(*actions)
  PermitOnlyActionsMatcher.new(*actions)
end