Sha256: 9856aacb441c7add33f39609bd1013bf76a7170c45666600bdc4320a863f591b

Contents?: true

Size: 836 Bytes

Versions: 2

Compression:

Stored size: 836 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)

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

            return false
          end
        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

2 entries across 2 versions & 1 rubygems

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