|
10 | 10 | {}
|
11 | 11 | end
|
12 | 12 |
|
13 |
| - let(:mongos) do |
14 |
| - false |
| 13 | + let(:cluster_double) do |
| 14 | + double('cluster') |
15 | 15 | end
|
16 | 16 |
|
17 |
| - let(:slave_ok) do |
| 17 | + let(:single?) do |
| 18 | + true |
| 19 | + end |
| 20 | + |
| 21 | + let(:mongos?) do |
18 | 22 | false
|
19 | 23 | end
|
20 | 24 |
|
| 25 | + let(:read_pref) do |
| 26 | + Mongo::ServerSelector.get |
| 27 | + end |
| 28 | + |
21 | 29 | let(:read_preferrable) do
|
22 | 30 | Class.new do
|
23 | 31 | include Mongo::Operation::ReadPreferrable
|
|
28 | 36 | end
|
29 | 37 | end
|
30 | 38 |
|
31 |
| - let(:cluster_double) do |
32 |
| - double('cluster') |
33 |
| - end |
34 |
| - |
35 | 39 | let(:context) do
|
36 | 40 | double('context').tap do |c|
|
37 | 41 | allow(c).to receive(:cluster).and_return(cluster_double)
|
38 |
| - allow(cluster_double).to receive(:single?).and_return(slave_ok) |
39 |
| - allow(c).to receive(:mongos?).and_return(mongos) |
| 42 | + allow(cluster_double).to receive(:single?).and_return(single?) |
| 43 | + allow(c).to receive(:mongos?).and_return(mongos?) |
40 | 44 | end
|
41 | 45 | end
|
42 | 46 |
|
|
65 | 69 | selector.merge(:$readPreference => read_pref.to_mongos)
|
66 | 70 | end
|
67 | 71 |
|
68 |
| - it 'returns a special selector' do |
| 72 | + it 'returns an unaltered special selector' do |
69 | 73 | expect(read_preferrable.send(:update_selector, context)).to eq(expected)
|
70 | 74 | end
|
71 | 75 | end
|
|
77 | 81 | Mongo::ServerSelector.get(:mode => mode)
|
78 | 82 | end
|
79 | 83 |
|
80 |
| - it 'returns a special selector' do |
| 84 | + it 'returns a selector' do |
81 | 85 | expect(read_preferrable.send(:update_selector, context)).to eq(selector)
|
82 | 86 | end
|
83 | 87 | end
|
84 | 88 |
|
85 | 89 | context 'when the server is a mongos' do
|
86 | 90 |
|
87 |
| - let(:mongos) do |
| 91 | + let(:mongos?) do |
88 | 92 | true
|
89 | 93 | end
|
90 | 94 |
|
|
136 | 140 |
|
137 | 141 | context 'when the server is not a mongos' do
|
138 | 142 |
|
| 143 | + let(:mongos?) do |
| 144 | + false |
| 145 | + end |
| 146 | + |
139 | 147 | let(:mode) do
|
140 | 148 | :secondary_preferred
|
141 | 149 | end
|
142 | 150 |
|
143 | 151 | it_behaves_like 'not a selector updater'
|
144 | 152 | end
|
145 | 153 |
|
146 |
| - context 'when the server context requires the slaveOk bit to be set' do |
147 |
| - |
148 |
| - let(:read_pref) do |
149 |
| - Mongo::ServerSelector.get(:mode => :secondary) |
150 |
| - end |
151 |
| - |
152 |
| - let(:expected) do |
153 |
| - { :flags => [ :slave_ok ] } |
154 |
| - end |
155 |
| - |
156 |
| - let(:slave_ok) do |
157 |
| - true |
158 |
| - end |
| 154 | + context 'when the server is not a mongos' do |
159 | 155 |
|
160 |
| - it 'sets the slave_ok flag' do |
161 |
| - expect(read_preferrable.send(:update_options, context)).to eq(expected) |
| 156 | + let(:mongos?) do |
| 157 | + false |
162 | 158 | end
|
163 |
| - end |
164 |
| - |
165 |
| - context 'when the server is not a mongos' do |
166 | 159 |
|
167 |
| - context 'when the read preference requires the slaveOk bit to be set' do |
| 160 | + context 'when the topology is Single' do |
168 | 161 |
|
169 |
| - let(:read_pref) do |
170 |
| - Mongo::ServerSelector.get(:mode => :secondary) |
| 162 | + let(:single?) do |
| 163 | + true |
171 | 164 | end
|
172 | 165 |
|
173 | 166 | let(:expected) do
|
|
179 | 172 | end
|
180 | 173 | end
|
181 | 174 |
|
182 |
| - context 'when the read preference does not require the slaveOk bit to be set' do |
| 175 | + context 'when the topology is not Single' do |
183 | 176 |
|
184 |
| - let(:read_pref) do |
185 |
| - Mongo::ServerSelector.get(:mode => :primary) |
| 177 | + let(:single?) do |
| 178 | + false |
| 179 | + end |
| 180 | + |
| 181 | + context 'when the read preference requires the slave_ok flag' do |
| 182 | + |
| 183 | + let(:read_pref) do |
| 184 | + Mongo::ServerSelector.get(:mode => :secondary) |
| 185 | + end |
| 186 | + |
| 187 | + let(:expected) do |
| 188 | + { :flags => [ :slave_ok ] } |
| 189 | + end |
| 190 | + |
| 191 | + it 'sets the slave_ok flag' do |
| 192 | + expect(read_preferrable.send(:update_options, context)).to eq(expected) |
| 193 | + end |
| 194 | + end |
| 195 | + |
| 196 | + context 'when the read preference does not require the slave_ok flag' do |
| 197 | + |
| 198 | + let(:read_pref) do |
| 199 | + Mongo::ServerSelector.get(:mode => :primary) |
| 200 | + end |
| 201 | + |
| 202 | + let(:expected) do |
| 203 | + { } |
| 204 | + end |
| 205 | + |
| 206 | + it 'does not set the slave_ok flag' do |
| 207 | + expect(read_preferrable.send(:update_options, context)).to eq(expected) |
| 208 | + end |
| 209 | + end |
| 210 | + end |
| 211 | + |
| 212 | + context 'when the topology is Single' do |
| 213 | + |
| 214 | + let(:single?) do |
| 215 | + true |
186 | 216 | end
|
187 | 217 |
|
188 | 218 | let(:expected) do
|
189 |
| - { } |
| 219 | + { :flags => [ :slave_ok ] } |
190 | 220 | end
|
191 | 221 |
|
192 | 222 | it 'sets the slave_ok flag' do
|
193 | 223 | expect(read_preferrable.send(:update_options, context)).to eq(expected)
|
194 | 224 | end
|
195 | 225 | end
|
196 | 226 | end
|
| 227 | + |
| 228 | + context 'when the server is a mongos' do |
| 229 | + |
| 230 | + let(:mongos?) do |
| 231 | + true |
| 232 | + end |
| 233 | + |
| 234 | + let(:expected) do |
| 235 | + { } |
| 236 | + end |
| 237 | + |
| 238 | + it 'does not set the slave_ok flag' do |
| 239 | + expect(read_preferrable.send(:update_options, context)).to eq(expected) |
| 240 | + end |
| 241 | + end |
197 | 242 | end
|
0 commit comments