Class: Shoulda::Matchers::ActiveRecord::AssociationMatchers::ThroughMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveRecord::AssociationMatchers::ThroughMatcher
- Defined in:
- lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb
Instance Attribute Summary collapse
-
#missing_option ⇒ Object
Returns the value of attribute missing_option.
Instance Method Summary collapse
- #association_set_properly? ⇒ Boolean
- #description ⇒ Object
-
#initialize(through, name) ⇒ ThroughMatcher
constructor
A new instance of ThroughMatcher.
- #matches?(subject) ⇒ Boolean
- #through_association_correct? ⇒ Boolean
- #through_association_exists? ⇒ Boolean
- #through_reflection ⇒ Object
Constructor Details
#initialize(through, name) ⇒ ThroughMatcher
Returns a new instance of ThroughMatcher.
9 10 11 12 13 |
# File 'lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb', line 9 def initialize(through, name) @through = through @name = name @missing_option = '' end |
Instance Attribute Details
#missing_option ⇒ Object
Returns the value of attribute missing_option.
7 8 9 |
# File 'lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb', line 7 def missing_option @missing_option end |
Instance Method Details
#association_set_properly? ⇒ Boolean
24 25 26 |
# 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 ⇒ Object
15 16 17 |
# File 'lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb', line 15 def description "through #{through}" end |
#matches?(subject) ⇒ Boolean
19 20 21 22 |
# 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? ⇒ Boolean
42 43 44 45 46 47 48 49 50 51 52 |
# 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? ⇒ Boolean
28 29 30 31 32 33 34 35 36 |
# 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 ⇒ Object
38 39 40 |
# File 'lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb', line 38 def through_reflection @_through_reflection ||= subject.reflect_on_association(through) end |