class Shoulda::Matchers::ActiveRecord::AssociationMatchers::ThroughMatcher

def association_set_properly?

def association_set_properly?
  through_association_exists? && through_association_correct?
end

def description

def description
  "through #{through}"
end

def initialize(through, name)

def initialize(through, name)
  @through = through
  @name = name
  @missing_option = ''
end

def matches?(subject)

def matches?(subject)
  self.subject = ModelReflector.new(subject, name)
  through.nil? || association_set_properly?
end

def option_verifier

def option_verifier
  @option_verifier ||= OptionVerifier.new(subject)
end

def through_association_correct?

def through_association_correct?
  if option_verifier.correct_for_string?(:through, through)
    true
  else
    self.missing_option =
      "Expected #{name} to have #{name} through #{through}, " +
      "but got it through #{option_verifier.actual_value_for(:through)}"
    false
  end
end

def through_association_exists?

def through_association_exists?
  if through_reflection.present?
    true
  else
    self.missing_option = "#{name} does not have any relationship to #{through}"
    false
  end
end

def through_reflection

def through_reflection
  @through_reflection ||= subject.reflect_on_association(through)
end