Sha256: 323705a8a70db965ae05dea42cb2959322575ea7cd50c4240cda61aef047146f

Contents?: true

Size: 1.43 KB

Versions: 18

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

require 'spec_helper'

describe 'Mongo::Collection#indexes / listIndexes prose tests' do
  let(:collection) do
    authorized_client['list-indexes-prose']
  end

  before do
    collection.drop
    collection.create
    collection.indexes.create_one({name: 1}, name: 'simple')
    collection.indexes.create_one({hello: 1, world: -1}, name: 'compound')
    collection.indexes.create_one({test: 1}, unique: true, name: 'unique')
    collection.insert_one(
      name: 'Stanley',
      hello: 'Yes',
      world: 'No',
      test: 'Always',
    )
  end

  let(:index_list) do
    collection.indexes.to_a
  end

  it 'returns all index names' do
    %w(simple compound unique).each do |name|
      index_list.detect do |spec|
        spec['name'] = name
      end.should be_a(Hash)
    end
  end

  it 'does not return duplicate or nonexistent index names' do
    # There are 4 total indexes: 3 that we explicitly defined + the
    # implicit index on _id.
    index_list.length.should == 4
  end

  it 'returns the unique flag for unique index' do
    unique_index = index_list.detect do |spec|
      spec['name'] == 'unique'
    end
    unique_index['unique'].should be true
  end

  it 'does not return the unique flag for non-unique index' do
    %w(simple compound).each do |name|
      index = index_list.detect do |spec|
        spec['name'] == name
      end
      index['unique'].should be nil
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mongo-2.16.4 spec/integration/collection_indexes_prose_spec.rb
mongo-2.17.4 spec/integration/collection_indexes_prose_spec.rb
mongo-2.18.3 spec/integration/collection_indexes_prose_spec.rb
mongo-2.18.2 spec/integration/collection_indexes_prose_spec.rb
mongo-2.17.3 spec/integration/collection_indexes_prose_spec.rb
mongo-2.18.1 spec/integration/collection_indexes_prose_spec.rb
mongo-2.18.0 spec/integration/collection_indexes_prose_spec.rb
mongo-2.17.2 spec/integration/collection_indexes_prose_spec.rb
mongo-2.16.3 spec/integration/collection_indexes_prose_spec.rb
mongo-2.18.0.beta1 spec/integration/collection_indexes_prose_spec.rb
mongo-2.16.2 spec/integration/collection_indexes_prose_spec.rb
mongo-2.17.1 spec/integration/collection_indexes_prose_spec.rb
mongo-2.16.1 spec/integration/collection_indexes_prose_spec.rb
mongo-2.17.0 spec/integration/collection_indexes_prose_spec.rb
mongo-2.16.0 spec/integration/collection_indexes_prose_spec.rb
mongo-2.15.1 spec/integration/collection_indexes_prose_spec.rb
mongo-2.16.0.alpha1 spec/integration/collection_indexes_prose_spec.rb
mongo-2.15.0 spec/integration/collection_indexes_prose_spec.rb