File: specifiable_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 (84 lines) | stat: -rw-r--r-- 1,670 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require 'spec_helper'

describe Mongo::Operation::Specifiable do

  let(:spec) do
    {}
  end

  let(:specifiable) do
    Class.new do
      include Mongo::Operation::Specifiable
    end.new(spec)
  end

  describe '#==' do

    context 'when the other object is a specifiable' do

      context 'when the specs are equal' do

        let(:other) do
          Class.new do
            include Mongo::Operation::Specifiable
          end.new(spec)
        end

        it 'returns true' do
          expect(specifiable).to eq(other)
        end
      end

      context 'when the specs are not equal' do

        let(:other) do
          Class.new do
            include Mongo::Operation::Specifiable
          end.new({ :db_name => 'test' })
        end

        it 'returns false' do
          expect(specifiable).to_not eq(other)
        end
      end
    end

    context 'when the other object is not a specifiable' do

      it 'returns false' do
        expect(specifiable).to_not eq('test')
      end
    end
  end

  describe '#read' do

    context 'when read is specified' do

      let(:spec) do
        {
          read: { mode: :secondary}
        }
      end

      let(:server_selector) do
        Mongo::ServerSelector.get(spec[:read])
      end

      it 'converts the read option to a ServerSelector' do
        expect(specifiable.read).to be_a(Mongo::ServerSelector::Secondary)
      end

      it 'uses the read option provided' do
        expect(specifiable.read).to eq(server_selector)
      end
    end

    context 'when read is not specified' do

      it 'returns nil' do
        expect(specifiable.read).to be_nil
      end
    end
  end
end