File: get_more_command_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 (179 lines) | stat: -rw-r--r-- 4,187 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
require 'spec_helper'

describe Mongo::Cursor::Builder::GetMoreCommand do

  describe '#specification' do

    let(:reply) do
      Mongo::Protocol::Reply.allocate
    end

    let(:result) do
      Mongo::Operation::Result.new(reply)
    end

    let(:cursor) do
      Mongo::Cursor.new(view, result, authorized_primary)
    end

    let(:builder) do
      described_class.new(cursor)
    end

    let(:specification) do
      builder.specification
    end

    let(:selector) do
      specification[:selector]
    end

    context 'when the operation has a session' do

      let(:view) do
        Mongo::Collection::View.new(authorized_collection)
      end

      let(:session) do
        double('session')
      end

      let(:builder) do
        described_class.new(cursor, session)
      end

      it 'adds the session to the specification' do
        expect(builder.specification[:session]).to be(session)
      end
    end

    shared_examples_for 'a getmore command builder' do

      it 'includes the database name' do
        expect(specification[:db_name]).to eq(TEST_DB)
      end

      it 'includes getmore with cursor id' do
        expect(selector[:getMore]).to eq(cursor.id)
      end

      it 'includes the collection name' do
        expect(selector[:collection]).to eq(TEST_COLL)
      end
    end

    context 'when the query is standard' do

      let(:view) do
        Mongo::Collection::View.new(authorized_collection)
      end

      it_behaves_like 'a getmore command builder'

      it 'does not include max time' do
        expect(selector[:maxTimeMS]).to be_nil
      end

      it 'does not include batch size' do
        expect(selector[:batchSize]).to be_nil
      end
    end

    context 'when the query has a batch size' do

      let(:view) do
        Mongo::Collection::View.new(authorized_collection, {}, batch_size: 10)
      end

      it_behaves_like 'a getmore command builder'

      it 'does not include max time' do
        expect(selector[:maxTimeMS]).to be_nil
      end

      it 'includes batch size' do
        expect(selector[:batchSize]).to eq(10)
      end
    end

    context 'when a max await time is specified' do

      context 'when the cursor is not tailable' do

        let(:view) do
          Mongo::Collection::View.new(authorized_collection, {}, max_await_time_ms: 100)
        end

        it_behaves_like 'a getmore command builder'

        it 'does not include max time' do
          expect(selector[:maxTimeMS]).to be_nil
        end

        it 'does not include max await time' do
          expect(selector[:maxAwaitTimeMS]).to be_nil
        end

        it 'does not include batch size' do
          expect(selector[:batchSize]).to be_nil
        end
      end

      context 'when the cursor is tailable' do

        context 'when await data is true' do

          let(:view) do
            Mongo::Collection::View.new(
              authorized_collection,
              {},
              await_data: true,
              tailable: true,
              max_await_time_ms: 100
            )
          end

          it_behaves_like 'a getmore command builder'

          it 'includes max time' do
            expect(selector[:maxTimeMS]).to eq(100)
          end

          it 'does not include max await time' do
            expect(selector[:maxAwaitTimeMS]).to be_nil
          end

          it 'does not include batch size' do
            expect(selector[:batchSize]).to be_nil
          end
        end

        context 'when await data is false' do

          let(:view) do
            Mongo::Collection::View.new(
              authorized_collection,
              {},
              tailable: true,
              max_await_time_ms: 100
            )
          end

          it_behaves_like 'a getmore command builder'

          it 'does not include max time' do
            expect(selector[:maxTimeMS]).to be_nil
          end

          it 'does not include max await time' do
            expect(selector[:maxAwaitTimeMS]).to be_nil
          end

          it 'does not include batch size' do
            expect(selector[:batchSize]).to be_nil
          end
        end
      end
    end
  end
end