class ActiveModelSerializersMatchers::AssociationMatcher::AssociationCheck

Attributes

matcher[R]
type[R]

Public Class Methods

new(matcher, type) click to toggle source
# File lib/active_model_serializers_matchers/association_matcher.rb, line 50
def initialize(matcher, type)
  @matcher = matcher
  @type = type
end

Public Instance Methods

description() click to toggle source
# File lib/active_model_serializers_matchers/association_matcher.rb, line 64
def description
  "#{ association_string } #{ matcher.root.inspect }"
end
fail?() click to toggle source
# File lib/active_model_serializers_matchers/association_matcher.rb, line 60
def fail?
  !pass?
end
failure_message() click to toggle source
# File lib/active_model_serializers_matchers/association_matcher.rb, line 68
def failure_message
  "expected #{ matcher.actual } to define a '#{ type } #{ matcher.root.inspect }' association"
end
pass?() click to toggle source
# File lib/active_model_serializers_matchers/association_matcher.rb, line 55
def pass?
  return false if matcher.root_association.nil?
  matcher.root_association.superclass == association_type
end

Private Instance Methods

association_string() click to toggle source
# File lib/active_model_serializers_matchers/association_matcher.rb, line 85
def association_string
  case type
  when :has_one
    'have one'
  when :has_many
    'have many'
  end
end
association_type() click to toggle source
# File lib/active_model_serializers_matchers/association_matcher.rb, line 74
def association_type
  case type
  when :has_one
    ActiveModel::Serializer::Associations::HasOne
  when :has_many
    ActiveModel::Serializer::Associations::HasMany
  else
    raise ArgumentError, "'#{type}' is an invalid association type."
  end
end