Sha256: cee5b0a886b53af024a8364762643be3a5f81d040d9162a5110c13326092a518

Contents?: true

Size: 1.53 KB

Versions: 13

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'

describe Mongo::Operation::Write::CreateIndex do

  describe '#execute' do

    context 'when the index is created' do

      let(:spec) do
        { key: { random: 1 }, name: 'random_1', unique: true }
      end

      let(:operation) do
        described_class.new(indexes: [ spec ], db_name: TEST_DB, coll_name: TEST_COLL)
      end

      let(:response) do
        operation.execute(authorized_primary)
      end

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

      it 'returns ok' do
        expect(response).to be_successful
      end
    end

    context 'when index creation fails' do

      let(:spec) do
        { key: { random: 1 }, name: 'random_1', unique: true }
      end

      let(:operation) do
        described_class.new(indexes: [ spec ], db_name: TEST_DB, coll_name: TEST_COLL)
      end

      let(:second_operation) do
        described_class.new(indexes: [ spec.merge(unique: false) ], db_name: TEST_DB, coll_name: TEST_COLL)
      end

      before do
        operation.execute(authorized_primary)
      end

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

      it 'raises an exception', if: write_command_enabled? do
        expect {
          second_operation.execute(authorized_primary)
        }.to raise_error(Mongo::Error::OperationFailure)
      end

      it 'does not raise an exception', unless: write_command_enabled? do
        expect(second_operation.execute(authorized_primary)).to be_successful
      end
    end
  end
end

Version data entries

13 entries across 11 versions & 2 rubygems

Version Path
mongo-2.5.0.beta spec/mongo/operation/write/create_index_spec.rb
mongo-2.4.3 spec/mongo/operation/write/create_index_spec.rb
tdiary-5.0.5 vendor/bundle/gems/mongo-2.4.1/spec/mongo/operation/write/create_index_spec.rb
tdiary-5.0.5 vendor/bundle/gems/mongo-2.4.2/spec/mongo/operation/write/create_index_spec.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mongo-2.4.1/spec/mongo/operation/write/create_index_spec.rb
mongo-2.4.2 spec/mongo/operation/write/create_index_spec.rb
tdiary-5.0.4 vendor/bundle/gems/mongo-2.4.1/spec/mongo/operation/write/create_index_spec.rb
mongo-2.4.1 spec/mongo/operation/write/create_index_spec.rb
mongo-2.4.0 spec/mongo/operation/write/create_index_spec.rb
mongo-2.3.1 spec/mongo/operation/write/create_index_spec.rb
mongo-2.4.0.rc1 spec/mongo/operation/write/create_index_spec.rb
mongo-2.4.0.rc0 spec/mongo/operation/write/create_index_spec.rb
mongo-2.3.0 spec/mongo/operation/write/create_index_spec.rb