Sha256: 28148708b685a14c2e44ed515f91034ded4593824c436b6e9659ba1f06df03d2

Contents?: true

Size: 1.37 KB

Versions: 14

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'

describe Mongo::Operation::Aggregate do

  let(:options) do
    {}
  end

  let(:selector) do
    { :aggregate => TEST_COLL,
      :pipeline => [],
    }
  end
  let(:spec) do
    { :selector => selector,
      :options => options,
      :db_name => SpecConfig.instance.test_db
    }
  end
  let(:op) { described_class.new(spec) }


  describe '#initialize' do

    context 'spec' do

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

  describe '#==' do

    context ' when two ops have different specs' do
      let(:other_selector) do
        { :aggregate => 'another_test_coll',
          :pipeline => [],
        }
      end
      let(:other_spec) do
        { :selector => other_selector,
          :options => options,
          :db_name => SpecConfig.instance.test_db,
        }
      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 aggregation fails' do

      let(:selector) do
        { :aggregate => TEST_COLL,
          :pipeline => [{ '$invalid' => 'operator' }],
        }
      end

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mongo-2.13.3 spec/mongo/operation/aggregate_spec.rb
mongo-2.14.1 spec/mongo/operation/aggregate_spec.rb
mongo-2.13.2 spec/mongo/operation/aggregate_spec.rb
mongo-2.14.0 spec/mongo/operation/aggregate_spec.rb
mongo-2.14.0.rc1 spec/mongo/operation/aggregate_spec.rb
mongo-2.13.1 spec/mongo/operation/aggregate_spec.rb
mongo-2.12.4 spec/mongo/operation/aggregate_spec.rb
mongo-2.13.0 spec/mongo/operation/aggregate_spec.rb
mongo-2.12.3 spec/mongo/operation/aggregate_spec.rb
mongo-2.13.0.rc1 spec/mongo/operation/aggregate_spec.rb
mongo-2.12.2 spec/mongo/operation/aggregate_spec.rb
mongo-2.13.0.beta1 spec/mongo/operation/aggregate_spec.rb
mongo-2.12.1 spec/mongo/operation/aggregate_spec.rb
mongo-2.12.0.rc0 spec/mongo/operation/aggregate_spec.rb