Sha256: 673d45d5f9c667605ce8766cb3743c555f8dc4ad49bebcde1017cdd870e8cb37

Contents?: true

Size: 1.94 KB

Versions: 10

Compression:

Stored size: 1.94 KB

Contents

require 'spec_helper'

describe Mongo::Operation::Command do

  let(:selector) { { :ismaster => 1 } }
  let(:options) { { :limit => -1 } }
  let(:spec) do
    { :selector => selector,
      :options     => options,
      :db_name  => TEST_DB
    }
  end
  let(:op) { described_class.new(spec) }

  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

  context '#merge' do

    let(:other_op) { described_class.new(spec) }

    it 'raises an exception' do
      expect{ op.merge(other_op) }.to raise_exception
    end
  end

  context '#merge!' do

    let(:other_op) { described_class.new(spec) }

    it 'raises an exception' do
      expect{ op.merge!(other_op) }.to raise_exception
    end
  end

  describe '#execute' do

    context 'when the command succeeds' do

      let(:response) do
        op.execute(authorized_primary.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)
        }.to raise_error(Mongo::Error::OperationFailure)
      end
    end

    context 'when a document exceeds max bson size' do

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

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mongo-2.1.0.rc0 spec/mongo/operation/commands/command_spec.rb
mongo-2.1.0.beta spec/mongo/operation/command_spec.rb
mongo-2.0.6 spec/mongo/operation/command_spec.rb
mongo-2.0.5 spec/mongo/operation/command_spec.rb
mongo-2.0.4 spec/mongo/operation/command_spec.rb
mongo-2.0.3 spec/mongo/operation/command_spec.rb
mongo-2.0.2 spec/mongo/operation/command_spec.rb
mongo-2.0.1 spec/mongo/operation/command_spec.rb
mongo-2.0.0 spec/mongo/operation/command_spec.rb
mongo-2.0.0.rc spec/mongo/operation/command_spec.rb