Class: Pundit::Matchers::PermitActionsMatcher
- Inherits:
-
ActionsMatcher
- Object
- BaseMatcher
- ActionsMatcher
- Pundit::Matchers::PermitActionsMatcher
- Defined in:
- lib/pundit/matchers/permit_actions_matcher.rb
Overview
This matcher tests whether a policy permits or forbids 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) ⇒ Boolean
Checks if the given policy forbids the expected actions.
-
#failure_message ⇒ String
Returns a failure message when the expected actions are forbidden.
-
#failure_message_when_negated ⇒ String
Returns a failure message when the expected actions are permitted.
-
#matches?(policy) ⇒ Boolean
Checks if the given policy permits 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/permit_actions_matcher.rb', line 12 def description "permit #{expected_actions}" end |
#does_not_match?(policy) ⇒ Boolean
Checks if the given policy forbids the expected actions.
35 36 37 38 39 40 41 42 43 44 |
# 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 ⇒ String
Returns a failure message when the expected actions are forbidden.
49 50 51 52 53 |
# File 'lib/pundit/matchers/permit_actions_matcher.rb', line 49 def = "expected '#{policy_info}' to permit #{expected_actions}," << " but forbade #{actual_actions}" << end |
#failure_message_when_negated ⇒ String
Returns a failure message when the expected actions are permitted.
58 59 60 61 62 |
# File 'lib/pundit/matchers/permit_actions_matcher.rb', line 58 def = "expected '#{policy_info}' to forbid #{expected_actions}," << " but permitted #{actual_actions}" << end |
#matches?(policy) ⇒ Boolean
Checks if the given policy permits the expected actions.
20 21 22 23 24 25 26 27 28 29 |
# 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 |