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

@private

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 9
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 24
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 15
def description
  "through #{through}"
end
matches?(subject) click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 19
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 42
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).to_s
    false
  end
end
through_association_exists?() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 28
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 38
def through_reflection
  @_through_reflection ||= subject.reflect_on_association(through)
end

Protected Instance Methods

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