# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 8 def initialize(through, name) @through = through @name = name @missing_option = '' end
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 23 def association_set_properly? through_association_exists? && through_association_correct? end
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 14 def description "through #{through}" end
# 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
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 40 def through_association_correct? if subject.option_set_properly?(through, :through) true else self.missing_option = "Expected #{name} to have #{name} through #{through}, " + "but got it through #{subject.option_string(:through)}" false end end
# 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
# File lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb, line 36 def through_reflection @through_reflection ||= subject.reflect_on_association(through) end