class Shoulda::Matchers::ActiveRecord::AssociationMatchers::DependentMatcher

@private

Attributes

dependent[RW]
missing_option[RW]
name[RW]
subject[RW]

Public Class Methods

new(dependent, name) click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb, line 9
def initialize(dependent, name)
  @dependent = dependent
  @name = name
  @missing_option = ''
end

Public Instance Methods

description() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb, line 15
def description
  "dependent => #{dependent}"
end
matches?(subject) click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb, line 19
def matches?(subject)
  self.subject = ModelReflector.new(subject, name)

  if option_matches?
    true
  else
    self.missing_option = generate_missing_option
    false
  end
end

Private Instance Methods

generate_missing_option() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb, line 51
def generate_missing_option
  [
    "#{name} should have",
    (dependent == true ? 'a' : dependent),
    'dependency'
  ].join(' ')
end
option_matches?() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb, line 40
def option_matches?
  option_verifier.correct_for?(option_type, :dependent, dependent)
end
option_type() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb, line 44
def option_type
  case dependent
    when true, false then :boolean
    else :string
  end
end
option_verifier() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb, line 36
def option_verifier
  @option_verifier ||= OptionVerifier.new(subject)
end