Sha256: e60ec6ceebdfacf5506b7fc12bf1bf1f7884511e9a80a52ec9c524e4978d9be2

Contents?: true

Size: 1.99 KB

Versions: 14

Compression:

Stored size: 1.99 KB

Contents

require "spec_helper"

describe Mongoid::Sessions::MongoUri do

  let(:single) do
    "mongodb://user:pass@localhost:27017/mongoid_test"
  end

  let(:multiple) do
    "mongodb://localhost:27017,localhost:27017/mongoid_test"
  end

  describe "#database" do

    let(:uri) do
      described_class.new(single)
    end

    it "returns the database name" do
      expect(uri.database).to eq("mongoid_test")
    end
  end

  describe "#hosts" do

    context "when a single node is provided" do

      let(:uri) do
        described_class.new(single)
      end

      it "returns an array with 1 node" do
        expect(uri.hosts).to eq([ "localhost:27017" ])
      end
    end

    context "when multiple nodes are provided" do

      let(:uri) do
        described_class.new(multiple)
      end

      it "returns an array with 2 nodes" do
        expect(uri.hosts).to eq([ "localhost:27017", "localhost:27017" ])
      end
    end
  end

  describe "#password" do

    let(:uri) do
      described_class.new(single)
    end

    it "returns the password" do
      expect(uri.password).to eq("pass")
    end
  end

  describe "#to_hash" do

    context "when a user and password are not provided" do

      let(:uri) do
        described_class.new(multiple)
      end

      it "does not include the username and password" do
        expect(uri.to_hash).to eq({
          hosts: [ "localhost:27017", "localhost:27017" ],
          database: "mongoid_test"
        })
      end
    end

    context "when a user and password are provided" do

      let(:uri) do
        described_class.new(single)
      end

      it "includes the username and password" do
        expect(uri.to_hash).to eq({
          hosts: [ "localhost:27017" ],
          database: "mongoid_test",
          username: "user",
          password: "pass"
        })
      end
    end
  end

  describe "#username" do

    let(:uri) do
      described_class.new(single)
    end

    it "returns the userame" do
      expect(uri.username).to eq("user")
    end
  end
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongoid-4.0.2/spec/mongoid/sessions/mongo_uri_spec.rb
mongoid-4.0.2 spec/mongoid/sessions/mongo_uri_spec.rb
mongoid-4.0.1 spec/mongoid/sessions/mongo_uri_spec.rb
mongoid-4.0.0 spec/mongoid/sessions/mongo_uri_spec.rb
mongoid-4.0.0.rc2 spec/mongoid/sessions/mongo_uri_spec.rb
mongoid-4.0.0.rc1 spec/mongoid/sessions/mongo_uri_spec.rb
mongoid-4.0.0.beta2 spec/mongoid/sessions/mongo_uri_spec.rb
mongoid-4.0.0.beta1 spec/mongoid/sessions/mongo_uri_spec.rb
mongoid-4.0.0.alpha2 spec/mongoid/sessions/mongo_uri_spec.rb
mongoid-4.0.0.alpha1 spec/mongoid/sessions/mongo_uri_spec.rb
sepastian-mongoid-rails4-4.0.1.alpha spec/mongoid/sessions/mongo_uri_spec.rb
sepastian-mongoid-rails4-4.0.0.alpha spec/mongoid/sessions/mongo_uri_spec.rb
mongoid_heroku_stable-4.0.0 spec/mongoid/sessions/mongo_uri_spec.rb
mongoid_rails4-4.0.0 spec/mongoid/sessions/mongo_uri_spec.rb