Sha256: 9a57d032ac49be14fb7483f0de225b4a19489f6e4a2ae5477b04e27a1e72b46e

Contents?: true

Size: 1.35 KB

Versions: 28

Compression:

Stored size: 1.35 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)
        }.to raise_error(Mongo::Error::OperationFailure)
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongo-2.8.0/spec/mongo/operation/aggregate_spec.rb
mongo-2.11.6 spec/mongo/operation/aggregate_spec.rb
mongo-2.10.5 spec/mongo/operation/aggregate_spec.rb
mongo-2.11.5 spec/mongo/operation/aggregate_spec.rb
mongo-2.11.4 spec/mongo/operation/aggregate_spec.rb
mongo-2.10.4 spec/mongo/operation/aggregate_spec.rb
mongo-2.11.3 spec/mongo/operation/aggregate_spec.rb
mongo-2.11.2 spec/mongo/operation/aggregate_spec.rb
mongo-2.11.1 spec/mongo/operation/aggregate_spec.rb
mongo-2.10.3 spec/mongo/operation/aggregate_spec.rb
mongo-2.11.0 spec/mongo/operation/aggregate_spec.rb
mongo-2.9.2 spec/mongo/operation/aggregate_spec.rb
mongo-2.10.2 spec/mongo/operation/aggregate_spec.rb
mongo-2.11.0.rc0 spec/mongo/operation/aggregate_spec.rb
mongo-2.10.1 spec/mongo/operation/aggregate_spec.rb
mongo-2.10.0 spec/mongo/operation/aggregate_spec.rb
mongo-2.9.1 spec/mongo/operation/aggregate_spec.rb
mongo-2.10.0.rc0 spec/mongo/operation/aggregate_spec.rb
mongo-2.9.1.rc0 spec/mongo/operation/aggregate_spec.rb
mongo-2.9.0 spec/mongo/operation/aggregate_spec.rb