File: flags_spec.rb

package info (click to toggle)
ruby-mongo 2.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,332 kB
  • sloc: ruby: 45,579; makefile: 5
file content (106 lines) | stat: -rw-r--r-- 2,206 bytes parent folder | download | duplicates (4)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require 'spec_helper'

describe Mongo::Collection::View::Builder::Flags do

  describe '.map_flags' do

    shared_examples_for 'a flag mapper' do

      let(:flags) do
        described_class.map_flags(options)
      end

      it 'maps allow partial results' do
        expect(flags).to include(:partial)
      end

      it 'maps oplog replay' do
        expect(flags).to include(:oplog_replay)
      end

      it 'maps no cursor timeout' do
        expect(flags).to include(:no_cursor_timeout)
      end

      it 'maps tailable' do
        expect(flags).to include(:tailable_cursor)
      end

      it 'maps await data' do
        expect(flags).to include(:await_data)
      end

      it 'maps exhaust' do
        expect(flags).to include(:exhaust)
      end
    end

    context 'when the options are standard' do

      let(:options) do
        {
          :allow_partial_results => true,
          :oplog_replay => true,
          :no_cursor_timeout => true,
          :tailable => true,
          :await_data => true,
          :exhaust => true
        }
      end

      it_behaves_like 'a flag mapper'
    end

    context 'when the options already have flags' do

      let(:options) do
        {
          :flags => [
            :partial,
            :oplog_replay,
            :no_cursor_timeout,
            :tailable_cursor,
            :await_data,
            :exhaust
          ]
        }
      end

      it_behaves_like 'a flag mapper'
    end

    context 'when the options include tailable_await' do

      let(:options) do
        { :tailable_await => true }
      end

      let(:flags) do
        described_class.map_flags(options)
      end

      it 'maps the await data option' do
        expect(flags).to include(:await_data)
      end

      it 'maps the tailable option' do
        expect(flags).to include(:tailable_cursor)
      end
    end

    context 'when the options provide a cursor type' do

      let(:options) do
        { :cursor_type => :await_data }
      end

      let(:flags) do
        described_class.map_flags(options)
      end

      it 'maps the cursor type to a flag' do
        expect(flags).to include(:await_data)
      end
    end
  end
end