Sha256: a1b82e0eaf25a92f228c822836ad60e4c9fdf78724c28c19b3f482acd5391b9f

Contents?: true

Size: 1.71 KB

Versions: 12

Compression:

Stored size: 1.71 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 a Primary ServerSelector object' do
        expect(specifiable.read).to eq(Mongo::ServerSelector.get(Mongo::ServerSelector::PRIMARY))
      end
    end
  end
end

Version data entries

12 entries across 10 versions & 2 rubygems

Version Path
mongo-2.4.3 spec/mongo/operation/specifiable_spec.rb
tdiary-5.0.5 vendor/bundle/gems/mongo-2.4.1/spec/mongo/operation/specifiable_spec.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mongo-2.4.1/spec/mongo/operation/specifiable_spec.rb
tdiary-5.0.5 vendor/bundle/gems/mongo-2.4.2/spec/mongo/operation/specifiable_spec.rb
mongo-2.4.2 spec/mongo/operation/specifiable_spec.rb
tdiary-5.0.4 vendor/bundle/gems/mongo-2.4.1/spec/mongo/operation/specifiable_spec.rb
mongo-2.4.1 spec/mongo/operation/specifiable_spec.rb
mongo-2.4.0 spec/mongo/operation/specifiable_spec.rb
mongo-2.3.1 spec/mongo/operation/specifiable_spec.rb
mongo-2.4.0.rc1 spec/mongo/operation/specifiable_spec.rb
mongo-2.4.0.rc0 spec/mongo/operation/specifiable_spec.rb
mongo-2.3.0 spec/mongo/operation/specifiable_spec.rb