Class: Pundit::Matchers::PermitAttributesMatcher
- Inherits:
-
AttributesMatcher
- Object
- BaseMatcher
- AttributesMatcher
- Pundit::Matchers::PermitAttributesMatcher
- Defined in:
- lib/pundit/matchers/permit_attributes_matcher.rb
Overview
This matcher tests whether a policy permits or forbids the mass assignment of the expected attributes.
Constant Summary
Constants inherited from AttributesMatcher
AttributesMatcher::ARGUMENTS_REQUIRED_ERROR, AttributesMatcher::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 mass assignment of the expected attributes.
-
#failure_message ⇒ String
The failure message when the expected attributes are forbidden.
-
#failure_message_when_negated ⇒ String
The failure message when the expected attributes are permitted.
-
#matches?(policy) ⇒ Boolean
Checks if the given policy permits the mass assignment of the expected attributes.
Methods inherited from AttributesMatcher
#ensure_single_attribute!, #for_action, #initialize
Constructor Details
This class inherits a constructor from Pundit::Matchers::AttributesMatcher
Instance Method Details
#description ⇒ String
A description of the matcher.
12 13 14 |
# File 'lib/pundit/matchers/permit_attributes_matcher.rb', line 12 def description "permit the mass assignment of #{expected_attributes}" end |
#does_not_match?(policy) ⇒ Boolean
Checks if the given policy forbids the mass assignment of the expected attributes.
32 33 34 35 36 37 38 |
# File 'lib/pundit/matchers/permit_attributes_matcher.rb', line 32 def does_not_match?(policy) setup_policy_info! policy @actual_attributes = expected_attributes & permitted_attributes(policy) actual_attributes.empty? end |
#failure_message ⇒ String
The failure message when the expected attributes are forbidden.
43 44 45 46 47 48 |
# File 'lib/pundit/matchers/permit_attributes_matcher.rb', line 43 def = "expected '#{policy_info}' to permit the mass assignment of #{expected_attributes}" << if .key?(:action) << ", but forbade the mass assignment of #{actual_attributes}" << end |
#failure_message_when_negated ⇒ String
The failure message when the expected attributes are permitted.
53 54 55 56 57 58 |
# File 'lib/pundit/matchers/permit_attributes_matcher.rb', line 53 def = "expected '#{policy_info}' to forbid the mass assignment of #{expected_attributes}" << if .key?(:action) << ", but permitted the mass assignment of #{actual_attributes}" << end |
#matches?(policy) ⇒ Boolean
Checks if the given policy permits the mass assignment of the expected attributes.
20 21 22 23 24 25 26 |
# File 'lib/pundit/matchers/permit_attributes_matcher.rb', line 20 def matches?(policy) setup_policy_info! policy @actual_attributes = expected_attributes - permitted_attributes(policy) actual_attributes.empty? end |