Sha256: f2f7228d218bf386dac58efdfd460a8d2ff89d5e3378648c78b82eb9fec57b33

Contents?: true

Size: 1020 Bytes

Versions: 1

Compression:

Stored size: 1020 Bytes

Contents

require "spec_helper"

describe Moped::ReadPreference::Secondary do

  describe "#name" do

    let(:preference) do
      described_class.new
    end

    it "returns secondary" do
      expect(preference.name).to eq(:secondary)
    end
  end

  describe "#select", replica_set: true do

    let(:preference) do
      described_class.new
    end

    context "when a secondary is available" do

      let(:cluster) do
        Moped::Cluster.new(@secondaries.map(&:address), {})
      end

      it "returns the secondary" do
        preference.with_node(cluster) do |node|
          expect(node).to be_secondary
        end
      end
    end

    context "when a secondary is not available" do

      let(:cluster) do
        Moped::Cluster.new([ @primary.address ], {})
      end

      before do
        @secondaries.each(&:stop)
      end

      it "raises an error" do
        expect {
          preference.with_node(cluster) {}
        }.to raise_error(Moped::Errors::ConnectionFailure)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/bundler/gems/moped-cf817ca58a85/spec/moped/read_preference/secondary_spec.rb