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.



64
65
66
67
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 64

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

Instance Method Details

#dependent(dependent) ⇒ Object



74
75
76
77
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 74

def dependent(dependent)
  @dependent = dependent
  self
end

#descriptionObject



103
104
105
106
107
108
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 103

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

#failure_messageObject



95
96
97
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 95

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

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
92
93
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 84

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

#negative_failure_messageObject



99
100
101
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 99

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

#through(through) ⇒ Object



69
70
71
72
# File 'lib/shoulda/active_record/matchers/association_matcher.rb', line 69

def through(through)
  @through = through
  self
end

#with_options(options) ⇒ Object



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

def with_options(options)
  @options = options
  self
end