Sha256: 08a7ab76bae28664b62b9d1f42e54f6c648c9745f37606e0f3375560b593c4a4

Contents?: true

Size: 755 Bytes

Versions: 1

Compression:

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

        if !@klass.index_options[@field.to_sym]
          @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 lib/matchers/document/have_index.rb