class Pundit::Matchers::PermitOnlyActionsMatcher
This matcher tests whether a policy permits only the expected actions.
Attributes
actual_actions[R]
extra_actions[R]
Public Instance Methods
description()
click to toggle source
A description of the matcher.
@return [String] A description of the matcher.
# File lib/pundit/matchers/permit_only_actions_matcher.rb, line 12 def description "permit only #{expected_actions}" end
does_not_match?(_policy)
click to toggle source
Raises a NotImplementedError @raise NotImplementedError @return [void]
# File lib/pundit/matchers/permit_only_actions_matcher.rb, line 33 def does_not_match?(_policy) raise NotImplementedError, format(AMBIGUOUS_NEGATED_MATCHER_ERROR, name: 'permit_only_actions') end
failure_message()
click to toggle source
The failure message when the expected actions and the permitted actions do not match.
@return [String] A failure message when the expected actions and the permitted actions do not match.
# File lib/pundit/matchers/permit_only_actions_matcher.rb, line 40 def failure_message message = +"expected '#{policy_info}' to permit only #{expected_actions}," message << " but permitted #{actual_actions}" unless actual_actions.empty? message << extra_message unless extra_actions.empty? message << user_message end
matches?(policy)
click to toggle source
Checks if the given policy permits only the expected actions.
@param policy [Object] The policy to test. @return [Boolean] True if the policy permits only the expected actions, false otherwise.
# File lib/pundit/matchers/permit_only_actions_matcher.rb, line 20 def matches?(policy) setup_policy_info! policy check_actions! @actual_actions = policy_info.permitted_actions - expected_actions @extra_actions = policy_info.forbidden_actions & expected_actions actual_actions.empty? && extra_actions.empty? end
Private Instance Methods
extra_message()
click to toggle source
# File lib/pundit/matchers/permit_only_actions_matcher.rb, line 51 def extra_message if actual_actions.empty? " but forbade #{extra_actions}" else " and forbade #{extra_actions}" end end