File: collection_indexes_prose_spec.rb

package info (click to toggle)
ruby-mongo 2.21.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,764 kB
  • sloc: ruby: 108,806; makefile: 5; sh: 2
file content (58 lines) | stat: -rw-r--r-- 1,467 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true
# rubocop:todo all

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