Sha256: 5d3ce1948175d8576a6388570718b35c76df9ab9adf4ffb9745909c5ad2dba9d

Contents?: true

Size: 1.01 KB

Versions: 12

Compression:

Stored size: 1.01 KB

Contents

module Shoulda
  module Matchers
    module ActiveRecord
      module AssociationMatchers
        # @private
        class CounterCacheMatcher
          attr_accessor :missing_option

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

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

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

            if option_verifier.correct_for_string?(
              :counter_cache,
              counter_cache,
            )
              true
            else
              self.missing_option = "#{name} should have #{description}"
              false
            end
          end

          protected

          attr_accessor :subject, :counter_cache, :name

          def option_verifier
            @_option_verifier ||= OptionVerifier.new(subject)
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
shoulda-matchers-6.3.1 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-6.3.0 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-6.2.0 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-6.1.0 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-6.0.0 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-5.3.0 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-5.2.0 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-5.1.0 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-5.0.0 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-5.0.0.rc1 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-4.5.1 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-4.5.0 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb