Sha256: b4674d063ed1337c2f765268a3fa5e6c2d41416c46759f722f8fb75430a9281f

Contents?: true

Size: 798 Bytes

Versions: 1

Compression:

Stored size: 798 Bytes

Contents

module Mongoid
  module Matchers
    class HaveIndexMatcher
      include Helpers

      def initialize(field)
        @field = field.to_s
      end

      def matches?(subject)
        @klass = class_of(subject)

        unless @klass.index_options[@field.to_sym] || @klass.index_options["#{@field}_id"]
          @error = "no index for #{@field.inspect}"

          return false
        end

        true
      end

      def failure_message
        "#{@klass} to #{description}, got #{@error}"
      end

      def negative_failure_message
        "#{@klass} to not #{description}, got #{@klass} to #{description}"
      end

      def description
        "have an index for #{@field.inspect}"
      end
    end

    def have_index_for(field)
      HaveIndexMatcher.new(field)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-minitest-0.0.3.1 lib/matchers/document/have_index.rb