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

Attributes

missing_option[RW]
name[RW]
subject[RW]
through[RW]

Public Class Methods

new(through, name) click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 8
def initialize(through, name)
  @through = through
  @name = name
  @missing_option = ''
end

Public Instance Methods

association_set_properly?() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 23
def association_set_properly?
  through_association_exists? && through_association_correct?
end
description() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 14
def description
  "through #{through}"
end
matches?(subject) click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 18
def matches?(subject)
  self.subject = ModelReflector.new(subject, name)
  through.nil? || association_set_properly?
end
through_association_correct?() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 40
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
through_association_exists?() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 27
def through_association_exists?
  if through_reflection.present?
    true
  else
    self.missing_option = "#{name} does not have any relationship to #{through}"
    false
  end
end
through_reflection() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 36
def through_reflection
  @through_reflection ||= subject.reflect_on_association(through)
end

Private Instance Methods

option_verifier() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 55
def option_verifier
  @option_verifier ||= OptionVerifier.new(subject)
end