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
Public Instance Methods
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
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
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
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
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
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
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
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
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
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