Sha256: 03e6d0765bcc96697c97d6fb4f655df52ba5ccc813f18569ff0c61d51525c000

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'

describe Mongo::Session::ServerSession do

  describe '#initialize' do

    it 'sets the last use variable to the current time' do
      expect(described_class.new.last_use).to be_within(0.2).of(Time.now)
    end

    it 'sets a UUID as the session id' do
      expect(described_class.new.instance_variable_get(:@session_id)).to be_a(BSON::Document)
      expect(described_class.new.session_id).to be_a(BSON::Document)
      expect(described_class.new.session_id[:id]).to be_a(BSON::Binary)
    end
  end

  describe '#next_txn_number' do

    it 'advances and returns the next transaction number' do
      expect(described_class.new.next_txn_num).to be(0)
    end

    context 'when the method is called multiple times' do

      let(:server_session) do
        described_class.new
      end

      before do
        server_session.next_txn_num
        server_session.next_txn_num
      end

      it 'advances and returns the next transaction number' do
        expect(server_session.next_txn_num).to be(2)
      end
    end
  end

  describe '#inspect' do

    let(:session) do
      described_class.new
    end

    it 'includes the Ruby object_id in the formatted string' do
      expect(session.inspect).to include(session.object_id.to_s)
    end

    it 'includes the session_id in the formatted string' do
      expect(session.inspect).to include(session.session_id.to_s)
    end

    it 'includes the last_use in the formatted string' do
      expect(session.inspect).to include(session.last_use.to_s)
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
mongo-2.5.3 spec/mongo/session/server_session_spec.rb
mongo-2.5.2 spec/mongo/session/server_session_spec.rb
tdiary-5.0.8 vendor/bundle/gems/mongo-2.5.1/spec/mongo/session/server_session_spec.rb
mongo-2.5.1 spec/mongo/session/server_session_spec.rb
mongo-2.5.0 spec/mongo/session/server_session_spec.rb