Sha256: 4b3ad774040a066495fc9589257f249acc034f2287296de5d4b77c4765667522

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require "spec_helper"

describe Moped::ReadPreference::PrimaryPreferred do

  describe "#name" do

    let(:preference) do
      described_class.new
    end

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

  describe "#with_node", replica_set: true do

    let(:preference) do
      described_class.new
    end

    context "when a primary is available" do

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

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

    context "when a primary is not available" do

      context "when a secondary is available" do

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

        before do
          @primary.stop
        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([], {})
        end

        it "raises an error" do
          expect {
            preference.with_node(cluster) {}
          }.to raise_error(Moped::Errors::ConnectionFailure)
        end
      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/primary_preferred_spec.rb