class Pundit::Matchers::PermitActionsMatcher

This matcher tests whether a policy permits or forbids the expected actions.

Attributes

actual_actions[R]

Public Instance Methods

description() click to toggle source

A description of the matcher.

@return [String] Description of the matcher.

# File lib/pundit/matchers/permit_actions_matcher.rb, line 12
def description
  "permit #{expected_actions}"
end
does_not_match?(policy) click to toggle source

Checks if the given policy forbids the expected actions.

@param policy [Object] The policy to test. @return [Boolean] True if the policy forbids the expected actions, false otherwise.

# File lib/pundit/matchers/permit_actions_matcher.rb, line 35
def does_not_match?(policy)
  setup_policy_info! policy
  check_actions!

  @actual_actions = expected_actions.select do |action|
    policy.public_send(:"#{action}?")
  end

  actual_actions.empty?
end
failure_message() click to toggle source

Returns a failure message when the expected actions are forbidden.

@return [String] A failure message when the expected actions are not forbidden.

# File lib/pundit/matchers/permit_actions_matcher.rb, line 49
def failure_message
  message = +"expected '#{policy_info}' to permit #{expected_actions},"
  message << " but forbade #{actual_actions}"
  message << user_message
end
failure_message_when_negated() click to toggle source

Returns a failure message when the expected actions are permitted.

@return [String] A failure message when the expected actions are permitted.

# File lib/pundit/matchers/permit_actions_matcher.rb, line 58
def failure_message_when_negated
  message = +"expected '#{policy_info}' to forbid #{expected_actions},"
  message << " but permitted #{actual_actions}"
  message << user_message
end
matches?(policy) click to toggle source

Checks if the given policy permits the expected actions.

@param policy [Object] The policy to test. @return [Boolean] True if the policy permits the expected actions, false otherwise.

# File lib/pundit/matchers/permit_actions_matcher.rb, line 20
def matches?(policy)
  setup_policy_info! policy
  check_actions!

  @actual_actions = expected_actions.reject do |action|
    policy.public_send(:"#{action}?")
  end

  actual_actions.empty?
end