Sha256: d002305fa2d72d3edd88e942bc4960091a2f5b8bd70807032c6cfb6938ab7329

Contents?: true

Size: 816 Bytes

Versions: 1

Compression:

Stored size: 816 Bytes

Contents

module Mongoid
  module Matchers
    class HaveIndexMatcher < Matcher
      def initialize *fields
        @fields = fields.map(&:to_sym)
      end

      def matches? subject
        @klass = class_of subject
        @klass.index_options.any? do |index, options|
          index.keys == @fields
        end
      end

      def failure_message
        "#{@klass} to #{description}, but only found indexes #{indexes.inspect}"
      end

      def negative_failure_message
        "#{@klass} to not #{description}, but found an index for #{@fields.inspect}"
      end

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

      def indexes
        @klass.index_options.keys.map(&:keys)
      end
    end

    def have_index_for *fields
      HaveIndexMatcher.new(*fields)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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