class Pundit::Matchers::PermitAttributesMatcher

This matcher tests whether a policy permits or forbids the mass assignment of the expected attributes.

Attributes

actual_attributes[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_attributes_matcher.rb, line 12
def description
  "permit the mass assignment of #{expected_attributes}"
end
does_not_match?(policy) click to toggle source

Checks if the given policy forbids the mass assignment of the expected attributes.

@param policy [Object] The policy to test. @return [Boolean] True if the policy forbids the mass assignment of the expected attributes, false otherwise.

# 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() click to toggle source

The failure message when the expected attributes are forbidden.

@return [String] A failure message when the expected attributes are not permitted.

# File lib/pundit/matchers/permit_attributes_matcher.rb, line 43
def failure_message
  message = +"expected '#{policy_info}' to permit the mass assignment of #{expected_attributes}"
  message << action_message if options.key?(:action)
  message << ", but forbade the mass assignment of #{actual_attributes}"
  message << user_message
end
failure_message_when_negated() click to toggle source

The failure message when the expected attributes are permitted.

@return [String] A failure message when the expected attributes are forbidden.

# File lib/pundit/matchers/permit_attributes_matcher.rb, line 53
def failure_message_when_negated
  message = +"expected '#{policy_info}' to forbid the mass assignment of #{expected_attributes}"
  message << action_message if options.key?(:action)
  message << ", but permitted the mass assignment of #{actual_attributes}"
  message << user_message
end
matches?(policy) click to toggle source

Checks if the given policy permits the mass assignment of the expected attributes.

@param policy [Object] The policy to test. @return [Boolean] True if the policy permits the mass assignment of the expected attributes, false otherwise.

# 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