Sha256: dce3aed58139d8b185c5d26cd0b19ffe0e48fb2e5c2af6764da40f1551b31bb8

Contents?: true

Size: 1.77 KB

Versions: 18

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

require 'spec_helper'

describe Mongo::Operation::Command do
  require_no_required_api_version

  let(:selector) { { :ping => 1 } }
  let(:options) { { :limit => -1 } }
  let(:spec) do
    { :selector => selector,
      :options     => options,
      :db_name  => SpecConfig.instance.test_db
    }
  end
  let(:op) { described_class.new(spec) }

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

  describe '#initialize' do

    it 'sets the spec' do
      expect(op.spec).to be(spec)
    end
  end

  describe '#==' do

    context 'when the ops have different specs' do

      let(:other_selector) { { :ping => 1 } }
      let(:other_spec) do
        { :selector => other_selector,
          :options => {},
          :db_name => 'test',
        }
      end
      let(:other) { described_class.new(other_spec) }

      it 'returns false' do
        expect(op).not_to eq(other)
      end
    end
  end

  describe '#execute' do

    context 'when the command succeeds' do

      let(:response) do
        op.execute(authorized_primary, context: context)
      end

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

    context 'when the command fails' do

      let(:selector) do
        { notacommand: 1 }
      end

      it 'raises an exception' do
        expect {
          op.execute(authorized_primary, context: context)
        }.to raise_error(Mongo::Error::OperationFailure)
      end
    end

    context 'when a document exceeds max bson size' do

      let(:selector) do
        { :hello => '1'*17000000 }
      end

      it 'raises an error' do
        expect {
          op.execute(authorized_primary, context: context)
        }.to raise_error(Mongo::Error::MaxBSONSize)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

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