Sha256: 15a15f57145d9a0d2928a5e6a628f53b298a90a97ce7b058285448ac5a1a74d2

Contents?: true

Size: 993 Bytes

Versions: 7

Compression:

Stored size: 993 Bytes

Contents

module Shoulda # :nodoc:
  module Matchers
    module ActiveRecord # :nodoc:
      module AssociationMatchers
        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

          private

          attr_accessor :subject, :counter_cache, :name

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shoulda-matchers-2.6.1 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-2.6.1.rc2 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-2.6.1.rc1 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-2.6.0 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-2.5.0 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-2.4.0 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb
shoulda-matchers-2.4.0.rc1 lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb