Class: Shoulda::Matchers::ActiveRecord::AssociationMatchers::CounterCacheMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(counter_cache, name) ⇒ CounterCacheMatcher

Returns a new instance of CounterCacheMatcher.



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

def initialize(counter_cache, name)
  @counter_cache = counter_cache
  @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/counter_cache_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/counter_cache_matcher.rb', line 15

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

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
# File 'lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb', line 19

def matches?(subject)
  self.subject = ModelReflector.new(subject, name)

  if correct_value?
    true
  else
    self.missing_option = "#{name} should have #{description}"
    false
  end
end