Sha256: 3043ebb50304ec41594c32576b0d2f4913ff59fdfc06bdd7eb746785e5ef3b20

Contents?: true

Size: 1.63 KB

Versions: 53

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

describe Mongo::Operation::Specifiable do

  let(:spec) do
    {}
  end

  let(:specifiable) do
    Class.new do
      include Mongo::Operation::Specifiable
    end.new(spec)
  end

  describe '#==' do

    context 'when the other object is a specifiable' do

      context 'when the specs are equal' do

        let(:other) do
          Class.new do
            include Mongo::Operation::Specifiable
          end.new(spec)
        end

        it 'returns true' do
          expect(specifiable).to eq(other)
        end
      end

      context 'when the specs are not equal' do

        let(:other) do
          Class.new do
            include Mongo::Operation::Specifiable
          end.new({ :db_name => 'test' })
        end

        it 'returns false' do
          expect(specifiable).to_not eq(other)
        end
      end
    end

    context 'when the other object is not a specifiable' do

      it 'returns false' do
        expect(specifiable).to_not eq('test')
      end
    end
  end

  describe '#read' do

    context 'when read is specified' do

      let(:spec) do
        {
          read: { mode: :secondary}
        }
      end

      let(:server_selector) do
        Mongo::ServerSelector.get(spec[:read])
      end

      it 'converts the read option to a ServerSelector' do
        expect(specifiable.read).to be_a(Mongo::ServerSelector::Secondary)
      end

      it 'uses the read option provided' do
        expect(specifiable.read).to eq(server_selector)
      end
    end

    context 'when read is not specified' do

      it 'returns nil' do
        expect(specifiable.read).to be_nil
      end
    end
  end
end

Version data entries

53 entries across 53 versions & 2 rubygems

Version Path
mongo-2.13.3 spec/mongo/operation/specifiable_spec.rb
mongo-2.14.1 spec/mongo/operation/specifiable_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongo-2.8.0/spec/mongo/operation/specifiable_spec.rb
mongo-2.15.0.alpha spec/mongo/operation/specifiable_spec.rb
mongo-2.13.2 spec/mongo/operation/specifiable_spec.rb
mongo-2.14.0 spec/mongo/operation/specifiable_spec.rb
mongo-2.14.0.rc1 spec/mongo/operation/specifiable_spec.rb
mongo-2.13.1 spec/mongo/operation/specifiable_spec.rb
mongo-2.12.4 spec/mongo/operation/specifiable_spec.rb
mongo-2.11.6 spec/mongo/operation/specifiable_spec.rb
mongo-2.13.0 spec/mongo/operation/specifiable_spec.rb
mongo-2.12.3 spec/mongo/operation/specifiable_spec.rb
mongo-2.13.0.rc1 spec/mongo/operation/specifiable_spec.rb
mongo-2.12.2 spec/mongo/operation/specifiable_spec.rb
mongo-2.10.5 spec/mongo/operation/specifiable_spec.rb
mongo-2.11.5 spec/mongo/operation/specifiable_spec.rb
mongo-2.13.0.beta1 spec/mongo/operation/specifiable_spec.rb
mongo-2.12.1 spec/mongo/operation/specifiable_spec.rb
mongo-2.12.0.rc0 spec/mongo/operation/specifiable_spec.rb
mongo-2.11.4 spec/mongo/operation/specifiable_spec.rb