File: indexes_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 (41 lines) | stat: -rw-r--r-- 951 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
# frozen_string_literal: true
# rubocop:todo all

require 'spec_helper'

describe Mongo::Operation::Indexes do
  require_no_required_api_version

  let(:context) { Mongo::Operation::Context.new }

  describe '#execute' do

    let(:index_spec) do
      { name: 1 }
    end

    before do
      authorized_collection.drop
      authorized_collection.insert_one(test: 1)
      authorized_collection.indexes.create_one(index_spec, unique: true)
    end

    after do
      authorized_collection.indexes.drop_one('name_1')
    end

    let(:operation) do
      described_class.new({ selector: { listIndexes: TEST_COLL },
                            coll_name: TEST_COLL,
                            db_name: SpecConfig.instance.test_db })
    end

    let(:indexes) do
      operation.execute(authorized_primary, context: context)
    end

    it 'returns the indexes for the collection' do
      expect(indexes.documents.size).to eq(2)
    end
  end
end