class Pundit::Matchers::PermitActionsMatcher
This matcher tests whether a policy permits or forbids the expected actions.
Attributes
Public Instance Methods
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
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
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
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
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