Class: Shoulda::Matchers::ActiveRecord::AssociationMatchers::DependentMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependent, name) ⇒ DependentMatcher

Returns a new instance of DependentMatcher.



9
10
11
12
13
# File 'lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb', line 9

def initialize(dependent, name)
  @dependent = dependent
  @name = name
  @missing_option = ''
end

Instance Attribute Details

#missing_optionObject

Returns the value of attribute missing_option.



7
8
9
# File 'lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb', line 7

def missing_option
  @missing_option
end

Instance Method Details

#descriptionObject



15
16
17
# File 'lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb', line 15

def description
  "dependent => #{dependent}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
# 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