Class: Shoulda::ActiveRecord::Matchers::AssociationMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/active_record/matchers/association_matcher.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(macro, name) ⇒ AssociationMatcher

Returns a new instance of AssociationMatcher.



56
57
58
59
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 56

def initialize(macro, name)
  @macro = macro
  @name  = name
end

Instance Method Details

#dependent(dependent) ⇒ Object



66
67
68
69
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 66

def dependent(dependent)
  @dependent = dependent
  self
end

#descriptionObject



89
90
91
92
93
94
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 89

def description
  description = "#{macro_description} #{@name}"
  description += " through #{@through}" if @through
  description += " dependent => #{@dependent}" if @dependent
  description
end

#failure_messageObject



81
82
83
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 81

def failure_message
  "Expected #{expectation} (#{@missing})"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
77
78
79
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 71

def matches?(subject)
  @subject = subject
  association_exists? &&
    macro_correct? &&
    foreign_key_exists? &&
    through_association_valid? &&
    dependent_correct? &&
    join_table_exists?
end

#negative_failure_messageObject



85
86
87
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 85

def negative_failure_message
  "Did not expect #{expectation}"
end

#through(through) ⇒ Object



61
62
63
64
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 61

def through(through)
  @through = through
  self
end