File: server_session_spec.rb

package info (click to toggle)
ruby-mongo 2.5.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 4,320 kB
  • sloc: ruby: 45,579; makefile: 5; sh: 2
file content (59 lines) | stat: -rw-r--r-- 1,552 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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