Class: Pundit::Matchers::ForbidOnlyActionsMatcher
- Inherits:
-
ActionsMatcher
- Object
- BaseMatcher
- ActionsMatcher
- Pundit::Matchers::ForbidOnlyActionsMatcher
- Defined in:
- lib/pundit/matchers/forbid_only_actions_matcher.rb
Overview
This matcher tests whether a policy forbids only the expected actions.
Constant Summary
Constants inherited from ActionsMatcher
ActionsMatcher::ACTIONS_NOT_IMPLEMENTED_ERROR, ActionsMatcher::ARGUMENTS_REQUIRED_ERROR, ActionsMatcher::ONE_ARGUMENT_REQUIRED_ERROR
Constants inherited from BaseMatcher
BaseMatcher::AMBIGUOUS_NEGATED_MATCHER_ERROR
Instance Method Summary collapse
-
#description ⇒ String
A description of the matcher.
-
#does_not_match?(_policy) ⇒ void
Raises a NotImplementedError.
-
#failure_message ⇒ String
The failure message when the expected actions and the forbidden actions do not match.
-
#matches?(policy) ⇒ Boolean
Checks if the given policy forbids only the expected actions.
Methods inherited from ActionsMatcher
#ensure_single_action!, #initialize
Constructor Details
This class inherits a constructor from Pundit::Matchers::ActionsMatcher
Instance Method Details
#description ⇒ String
A description of the matcher.
12 13 14 |
# File 'lib/pundit/matchers/forbid_only_actions_matcher.rb', line 12 def description "forbid only #{expected_actions}" end |
#does_not_match?(_policy) ⇒ void
This method returns an undefined value.
Raises a NotImplementedError
33 34 35 |
# File 'lib/pundit/matchers/forbid_only_actions_matcher.rb', line 33 def does_not_match?(_policy) raise NotImplementedError, format(AMBIGUOUS_NEGATED_MATCHER_ERROR, name: 'forbid_only_actions') end |
#failure_message ⇒ String
The failure message when the expected actions and the forbidden actions do not match.
40 41 42 43 44 45 |
# File 'lib/pundit/matchers/forbid_only_actions_matcher.rb', line 40 def = "expected '#{policy_info}' to forbid only #{expected_actions}," << " but forbade #{actual_actions}" unless actual_actions.empty? << unless extra_actions.empty? << end |
#matches?(policy) ⇒ Boolean
Checks if the given policy forbids only the expected actions.
20 21 22 23 24 25 26 27 28 |
# File 'lib/pundit/matchers/forbid_only_actions_matcher.rb', line 20 def matches?(policy) setup_policy_info! policy check_actions! @actual_actions = policy_info.forbidden_actions - expected_actions @extra_actions = policy_info.permitted_actions & expected_actions actual_actions.empty? && extra_actions.empty? end |