mongo 2.2.7 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE +1 -1
  5. data/README.md +1 -1
  6. data/Rakefile +1 -1
  7. data/lib/mongo.rb +1 -1
  8. data/lib/mongo/address.rb +1 -1
  9. data/lib/mongo/address/ipv4.rb +1 -1
  10. data/lib/mongo/address/ipv6.rb +1 -1
  11. data/lib/mongo/address/unix.rb +1 -1
  12. data/lib/mongo/auth.rb +1 -1
  13. data/lib/mongo/auth/cr.rb +1 -1
  14. data/lib/mongo/auth/ldap.rb +1 -1
  15. data/lib/mongo/auth/roles.rb +1 -1
  16. data/lib/mongo/auth/user.rb +1 -1
  17. data/lib/mongo/auth/user/view.rb +5 -5
  18. data/lib/mongo/auth/x509.rb +1 -1
  19. data/lib/mongo/bson.rb +1 -1
  20. data/lib/mongo/bulk_write.rb +4 -4
  21. data/lib/mongo/bulk_write/combineable.rb +1 -1
  22. data/lib/mongo/bulk_write/ordered_combiner.rb +1 -1
  23. data/lib/mongo/bulk_write/result.rb +1 -1
  24. data/lib/mongo/bulk_write/result_combiner.rb +1 -1
  25. data/lib/mongo/bulk_write/transformable.rb +1 -1
  26. data/lib/mongo/bulk_write/unordered_combiner.rb +1 -1
  27. data/lib/mongo/bulk_write/validatable.rb +1 -1
  28. data/lib/mongo/client.rb +2 -2
  29. data/lib/mongo/cluster.rb +15 -3
  30. data/lib/mongo/cluster/cursor_reaper.rb +174 -0
  31. data/lib/mongo/cluster/topology.rb +1 -1
  32. data/lib/mongo/cluster/topology/replica_set.rb +1 -1
  33. data/lib/mongo/cluster/topology/sharded.rb +1 -1
  34. data/lib/mongo/cluster/topology/single.rb +1 -1
  35. data/lib/mongo/cluster/topology/unknown.rb +1 -1
  36. data/lib/mongo/collection.rb +5 -4
  37. data/lib/mongo/collection/view.rb +4 -4
  38. data/lib/mongo/collection/view/aggregation.rb +2 -2
  39. data/lib/mongo/collection/view/builder.rb +1 -1
  40. data/lib/mongo/collection/view/builder/aggregation.rb +1 -1
  41. data/lib/mongo/collection/view/builder/find_command.rb +1 -1
  42. data/lib/mongo/collection/view/builder/flags.rb +1 -1
  43. data/lib/mongo/collection/view/builder/map_reduce.rb +1 -1
  44. data/lib/mongo/collection/view/builder/modifiers.rb +1 -1
  45. data/lib/mongo/collection/view/builder/op_query.rb +1 -1
  46. data/lib/mongo/collection/view/explainable.rb +1 -1
  47. data/lib/mongo/collection/view/immutable.rb +1 -1
  48. data/lib/mongo/collection/view/iterable.rb +2 -2
  49. data/lib/mongo/collection/view/map_reduce.rb +3 -3
  50. data/lib/mongo/collection/view/readable.rb +23 -6
  51. data/lib/mongo/collection/view/writable.rb +3 -3
  52. data/lib/mongo/cursor.rb +50 -7
  53. data/lib/mongo/cursor/builder.rb +1 -1
  54. data/lib/mongo/cursor/builder/get_more_command.rb +1 -1
  55. data/lib/mongo/cursor/builder/kill_cursors_command.rb +29 -1
  56. data/lib/mongo/cursor/builder/op_get_more.rb +1 -1
  57. data/lib/mongo/cursor/builder/op_kill_cursors.rb +29 -1
  58. data/lib/mongo/database.rb +4 -4
  59. data/lib/mongo/database/view.rb +2 -2
  60. data/lib/mongo/dbref.rb +4 -3
  61. data/lib/mongo/error.rb +1 -1
  62. data/lib/mongo/error/bulk_write_error.rb +1 -1
  63. data/lib/mongo/error/closed_stream.rb +1 -1
  64. data/lib/mongo/error/extra_file_chunk.rb +1 -1
  65. data/lib/mongo/error/file_not_found.rb +1 -1
  66. data/lib/mongo/error/invalid_bulk_operation.rb +1 -1
  67. data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -1
  68. data/lib/mongo/error/invalid_collection_name.rb +1 -1
  69. data/lib/mongo/error/invalid_database_name.rb +1 -1
  70. data/lib/mongo/error/invalid_document.rb +1 -1
  71. data/lib/mongo/error/invalid_file.rb +1 -1
  72. data/lib/mongo/error/invalid_file_revision.rb +1 -1
  73. data/lib/mongo/error/invalid_nonce.rb +1 -1
  74. data/lib/mongo/error/invalid_replacement_document.rb +1 -1
  75. data/lib/mongo/error/invalid_server_preference.rb +1 -1
  76. data/lib/mongo/error/invalid_signature.rb +1 -1
  77. data/lib/mongo/error/invalid_update_document.rb +1 -1
  78. data/lib/mongo/error/invalid_uri.rb +1 -1
  79. data/lib/mongo/error/invalid_write_concern.rb +1 -1
  80. data/lib/mongo/error/max_bson_size.rb +1 -1
  81. data/lib/mongo/error/max_message_size.rb +1 -1
  82. data/lib/mongo/error/missing_file_chunk.rb +1 -1
  83. data/lib/mongo/error/multi_index_drop.rb +1 -1
  84. data/lib/mongo/error/need_primary_server.rb +1 -1
  85. data/lib/mongo/error/no_server_available.rb +4 -2
  86. data/lib/mongo/error/operation_failure.rb +1 -1
  87. data/lib/mongo/error/parser.rb +1 -1
  88. data/lib/mongo/error/socket_error.rb +1 -1
  89. data/lib/mongo/error/socket_timeout_error.rb +1 -1
  90. data/lib/mongo/error/unchangeable_collection_option.rb +1 -1
  91. data/lib/mongo/error/unexpected_chunk_length.rb +1 -1
  92. data/lib/mongo/error/unexpected_response.rb +1 -1
  93. data/lib/mongo/error/unsupported_features.rb +1 -1
  94. data/lib/mongo/event.rb +1 -1
  95. data/lib/mongo/event/description_changed.rb +1 -1
  96. data/lib/mongo/event/publisher.rb +1 -1
  97. data/lib/mongo/event/subscriber.rb +1 -1
  98. data/lib/mongo/grid.rb +1 -1
  99. data/lib/mongo/grid/file.rb +6 -2
  100. data/lib/mongo/grid/file/chunk.rb +6 -4
  101. data/lib/mongo/grid/file/info.rb +7 -3
  102. data/lib/mongo/grid/fs_bucket.rb +12 -6
  103. data/lib/mongo/grid/stream.rb +1 -1
  104. data/lib/mongo/grid/stream/read.rb +2 -4
  105. data/lib/mongo/grid/stream/write.rb +4 -3
  106. data/lib/mongo/index.rb +1 -1
  107. data/lib/mongo/index/view.rb +5 -4
  108. data/lib/mongo/loggable.rb +1 -1
  109. data/lib/mongo/logger.rb +1 -1
  110. data/lib/mongo/monitoring.rb +1 -1
  111. data/lib/mongo/operation.rb +1 -1
  112. data/lib/mongo/operation/commands.rb +1 -1
  113. data/lib/mongo/operation/commands/aggregate.rb +7 -7
  114. data/lib/mongo/operation/commands/aggregate/result.rb +1 -1
  115. data/lib/mongo/operation/commands/collections_info.rb +10 -9
  116. data/lib/mongo/operation/commands/collections_info/result.rb +1 -1
  117. data/lib/mongo/operation/commands/command.rb +1 -1
  118. data/lib/mongo/operation/commands/indexes.rb +12 -11
  119. data/lib/mongo/operation/commands/list_collections.rb +1 -1
  120. data/lib/mongo/operation/commands/list_collections/result.rb +1 -1
  121. data/lib/mongo/operation/commands/list_indexes.rb +1 -1
  122. data/lib/mongo/operation/commands/list_indexes/result.rb +1 -1
  123. data/lib/mongo/operation/commands/map_reduce.rb +1 -1
  124. data/lib/mongo/operation/commands/map_reduce/result.rb +1 -1
  125. data/lib/mongo/operation/commands/user_query.rb +11 -10
  126. data/lib/mongo/operation/commands/users_info.rb +2 -2
  127. data/lib/mongo/operation/commands/users_info/result.rb +1 -1
  128. data/lib/mongo/operation/executable.rb +8 -7
  129. data/lib/mongo/operation/kill_cursors.rb +2 -2
  130. data/lib/mongo/operation/limited.rb +1 -1
  131. data/lib/mongo/operation/read.rb +1 -1
  132. data/lib/mongo/operation/read/get_more.rb +2 -2
  133. data/lib/mongo/operation/read/query.rb +1 -1
  134. data/lib/mongo/operation/read/query/result.rb +1 -1
  135. data/lib/mongo/operation/read_preference.rb +10 -10
  136. data/lib/mongo/operation/result.rb +1 -1
  137. data/lib/mongo/operation/specifiable.rb +2 -2
  138. data/lib/mongo/operation/write.rb +1 -1
  139. data/lib/mongo/operation/write/bulk.rb +1 -1
  140. data/lib/mongo/operation/write/bulk/bulkable.rb +9 -9
  141. data/lib/mongo/operation/write/bulk/delete.rb +3 -3
  142. data/lib/mongo/operation/write/bulk/delete/result.rb +1 -1
  143. data/lib/mongo/operation/write/bulk/insert.rb +5 -5
  144. data/lib/mongo/operation/write/bulk/insert/result.rb +1 -1
  145. data/lib/mongo/operation/write/bulk/legacy_mergable.rb +1 -1
  146. data/lib/mongo/operation/write/bulk/mergable.rb +1 -1
  147. data/lib/mongo/operation/write/bulk/update.rb +3 -3
  148. data/lib/mongo/operation/write/bulk/update/result.rb +1 -1
  149. data/lib/mongo/operation/write/command.rb +1 -1
  150. data/lib/mongo/operation/write/command/create_index.rb +1 -1
  151. data/lib/mongo/operation/write/command/create_user.rb +1 -1
  152. data/lib/mongo/operation/write/command/delete.rb +1 -1
  153. data/lib/mongo/operation/write/command/drop_index.rb +1 -1
  154. data/lib/mongo/operation/write/command/insert.rb +11 -1
  155. data/lib/mongo/operation/write/command/remove_user.rb +1 -1
  156. data/lib/mongo/operation/write/command/update.rb +1 -1
  157. data/lib/mongo/operation/write/command/update_user.rb +1 -1
  158. data/lib/mongo/operation/write/command/writable.rb +7 -6
  159. data/lib/mongo/operation/write/create_index.rb +1 -1
  160. data/lib/mongo/operation/write/create_user.rb +1 -1
  161. data/lib/mongo/operation/write/delete.rb +1 -1
  162. data/lib/mongo/operation/write/delete/result.rb +1 -1
  163. data/lib/mongo/operation/write/drop_index.rb +5 -5
  164. data/lib/mongo/operation/write/gle.rb +3 -3
  165. data/lib/mongo/operation/write/idable.rb +1 -1
  166. data/lib/mongo/operation/write/insert.rb +5 -5
  167. data/lib/mongo/operation/write/insert/result.rb +1 -1
  168. data/lib/mongo/operation/write/remove_user.rb +1 -1
  169. data/lib/mongo/operation/write/update.rb +1 -1
  170. data/lib/mongo/operation/write/update/result.rb +1 -1
  171. data/lib/mongo/operation/write/update_user.rb +1 -1
  172. data/lib/mongo/operation/write/write_command_enabled.rb +10 -9
  173. data/lib/mongo/protocol/bit_vector.rb +2 -2
  174. data/lib/mongo/protocol/delete.rb +1 -1
  175. data/lib/mongo/protocol/get_more.rb +1 -1
  176. data/lib/mongo/protocol/insert.rb +5 -1
  177. data/lib/mongo/protocol/kill_cursors.rb +1 -1
  178. data/lib/mongo/protocol/message.rb +9 -5
  179. data/lib/mongo/protocol/query.rb +1 -1
  180. data/lib/mongo/protocol/reply.rb +1 -1
  181. data/lib/mongo/protocol/serializers.rb +8 -8
  182. data/lib/mongo/protocol/update.rb +1 -1
  183. data/lib/mongo/server.rb +40 -3
  184. data/lib/mongo/server/connectable.rb +1 -1
  185. data/lib/mongo/server/connection.rb +4 -2
  186. data/lib/mongo/server/connection_pool.rb +1 -1
  187. data/lib/mongo/server/connection_pool/queue.rb +1 -1
  188. data/lib/mongo/server/context.rb +3 -1
  189. data/lib/mongo/server/description.rb +1 -1
  190. data/lib/mongo/server/description/inspector/description_changed.rb +1 -1
  191. data/lib/mongo/server/monitor.rb +1 -1
  192. data/lib/mongo/server_selector.rb +2 -1
  193. data/lib/mongo/server_selector/nearest.rb +1 -1
  194. data/lib/mongo/server_selector/primary.rb +1 -1
  195. data/lib/mongo/server_selector/primary_preferred.rb +1 -1
  196. data/lib/mongo/server_selector/secondary.rb +1 -1
  197. data/lib/mongo/server_selector/secondary_preferred.rb +1 -1
  198. data/lib/mongo/server_selector/selectable.rb +12 -7
  199. data/lib/mongo/socket.rb +1 -1
  200. data/lib/mongo/socket/ssl.rb +1 -1
  201. data/lib/mongo/socket/tcp.rb +1 -1
  202. data/lib/mongo/socket/unix.rb +1 -1
  203. data/lib/mongo/uri.rb +1 -1
  204. data/lib/mongo/version.rb +2 -2
  205. data/lib/mongo/write_concern/acknowledged.rb +1 -1
  206. data/lib/mongo/write_concern/normalizable.rb +1 -1
  207. data/lib/mongo/write_concern/unacknowledged.rb +1 -1
  208. data/mongo.gemspec +1 -1
  209. data/spec/mongo/client_spec.rb +2 -2
  210. data/spec/mongo/cluster/cursor_reaper_spec.rb +216 -0
  211. data/spec/mongo/cluster_spec.rb +36 -5
  212. data/spec/mongo/collection/view/aggregation_spec.rb +2 -2
  213. data/spec/mongo/collection/view/map_reduce_spec.rb +2 -2
  214. data/spec/mongo/collection/view/readable_spec.rb +203 -5
  215. data/spec/mongo/collection/view_spec.rb +10 -0
  216. data/spec/mongo/collection_spec.rb +64 -18
  217. data/spec/mongo/cursor_spec.rb +89 -0
  218. data/spec/mongo/database_spec.rb +79 -13
  219. data/spec/mongo/grid/fs_bucket_spec.rb +119 -1
  220. data/spec/mongo/grid/stream/write_spec.rb +63 -12
  221. data/spec/mongo/index/view_spec.rb +19 -0
  222. data/spec/mongo/operation/commands/aggregate_spec.rb +10 -7
  223. data/spec/mongo/operation/commands/collections_info_spec.rb +1 -1
  224. data/spec/mongo/operation/commands/command_spec.rb +3 -3
  225. data/spec/mongo/operation/commands/indexes_spec.rb +1 -1
  226. data/spec/mongo/operation/commands/map_reduce_spec.rb +2 -2
  227. data/spec/mongo/operation/kill_cursors_spec.rb +10 -19
  228. data/spec/mongo/operation/read/get_more_spec.rb +13 -25
  229. data/spec/mongo/operation/read/query_spec.rb +26 -30
  230. data/spec/mongo/operation/read_preference_spec.rb +11 -11
  231. data/spec/mongo/operation/specifiable_spec.rb +31 -0
  232. data/spec/mongo/operation/write/bulk/delete_spec.rb +16 -18
  233. data/spec/mongo/operation/write/bulk/insert_spec.rb +17 -18
  234. data/spec/mongo/operation/write/bulk/update_spec.rb +20 -25
  235. data/spec/mongo/operation/write/command/delete_spec.rb +26 -32
  236. data/spec/mongo/operation/write/command/insert_spec.rb +24 -31
  237. data/spec/mongo/operation/write/command/update_spec.rb +24 -32
  238. data/spec/mongo/operation/write/create_index_spec.rb +4 -4
  239. data/spec/mongo/operation/write/create_user_spec.rb +3 -3
  240. data/spec/mongo/operation/write/delete_spec.rb +51 -22
  241. data/spec/mongo/operation/write/drop_index_spec.rb +2 -2
  242. data/spec/mongo/operation/write/insert_spec.rb +42 -11
  243. data/spec/mongo/operation/write/remove_user_spec.rb +4 -4
  244. data/spec/mongo/operation/write/update_spec.rb +34 -6
  245. data/spec/mongo/operation/write/update_user_spec.rb +1 -1
  246. data/spec/mongo/server/connection_spec.rb +22 -14
  247. data/spec/mongo/server_selection_spec.rb +2 -2
  248. data/spec/mongo/server_selector/nearest_spec.rb +4 -4
  249. data/spec/mongo/server_selector/primary_preferred_spec.rb +4 -4
  250. data/spec/mongo/server_selector/primary_spec.rb +2 -2
  251. data/spec/mongo/server_selector/secondary_preferred_spec.rb +4 -4
  252. data/spec/mongo/server_selector/secondary_spec.rb +3 -3
  253. data/spec/mongo/server_selector_spec.rb +82 -3
  254. data/spec/mongo/server_spec.rb +0 -20
  255. data/spec/support/command_monitoring.rb +1 -1
  256. data/spec/support/connection_string.rb +1 -1
  257. data/spec/support/crud.rb +1 -1
  258. data/spec/support/crud/read.rb +1 -1
  259. data/spec/support/crud/write.rb +1 -1
  260. data/spec/support/gridfs.rb +1 -1
  261. data/spec/support/shared/server_selector.rb +3 -3
  262. metadata +7 -10
  263. metadata.gz.sig +0 -0
  264. data/lib/csasl/csasl.bundle +0 -0
  265. data/spec/mongo/operation/write/response_spec.rb +0 -85
  266. data/spec/support/shared/operation.rb +0 -100
@@ -1,16 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongo::Operation::Write::Bulk::Insert do
4
- include_context 'operation'
5
4
 
6
5
  let(:documents) do
7
6
  [{ :name => 'test' }]
8
7
  end
9
8
 
9
+ let(:write_concern) do
10
+ Mongo::WriteConcern.get(WRITE_CONCERN)
11
+ end
12
+
10
13
  let(:spec) do
11
14
  { documents: documents,
12
- db_name: db_name,
13
- coll_name: coll_name,
15
+ db_name: authorized_collection.database.name,
16
+ coll_name: authorized_collection.name,
14
17
  write_concern: write_concern
15
18
  }
16
19
  end
@@ -84,7 +87,7 @@ describe Mongo::Operation::Write::Bulk::Insert do
84
87
  end
85
88
 
86
89
  let(:inserted_ids) do
87
- op.execute(authorized_primary.context).inserted_ids
90
+ op.execute(authorized_primary).inserted_ids
88
91
  end
89
92
 
90
93
  let(:collection_ids) do
@@ -113,7 +116,7 @@ describe Mongo::Operation::Write::Bulk::Insert do
113
116
  context 'when the insert succeeds' do
114
117
 
115
118
  let(:response) do
116
- op.execute(authorized_primary.context)
119
+ op.execute(authorized_primary)
117
120
  end
118
121
 
119
122
  it 'inserts the documents into the database', if: write_command_enabled? do
@@ -135,7 +138,7 @@ describe Mongo::Operation::Write::Bulk::Insert do
135
138
  end
136
139
 
137
140
  let(:response) do
138
- op.execute(authorized_primary.context)
141
+ op.execute(authorized_primary)
139
142
  end
140
143
 
141
144
  it 'inserts the documents into the database', if: write_command_enabled? do
@@ -156,8 +159,8 @@ describe Mongo::Operation::Write::Bulk::Insert do
156
159
 
157
160
  let(:spec) do
158
161
  { documents: documents,
159
- db_name: db_name,
160
- coll_name: coll_name,
162
+ db_name: authorized_collection.database.name,
163
+ coll_name: authorized_collection.name,
161
164
  write_concern: write_concern,
162
165
  ordered: true
163
166
  }
@@ -176,7 +179,7 @@ describe Mongo::Operation::Write::Bulk::Insert do
176
179
  context 'when the insert fails' do
177
180
 
178
181
  it 'aborts after first error' do
179
- failing_insert.execute(authorized_primary.context)
182
+ failing_insert.execute(authorized_primary)
180
183
  expect(authorized_collection.find.count).to eq(1)
181
184
  end
182
185
  end
@@ -191,7 +194,7 @@ describe Mongo::Operation::Write::Bulk::Insert do
191
194
  context 'when the insert fails' do
192
195
 
193
196
  it 'aborts after first error' do
194
- failing_insert.execute(authorized_primary.context)
197
+ failing_insert.execute(authorized_primary)
195
198
  expect(authorized_collection.find.count).to eq(1)
196
199
  end
197
200
  end
@@ -206,8 +209,8 @@ describe Mongo::Operation::Write::Bulk::Insert do
206
209
 
207
210
  let(:spec) do
208
211
  { documents: documents,
209
- db_name: db_name,
210
- coll_name: coll_name,
212
+ db_name: authorized_collection.database.name,
213
+ coll_name: authorized_collection.name,
211
214
  write_concern: write_concern,
212
215
  ordered: false
213
216
  }
@@ -219,14 +222,10 @@ describe Mongo::Operation::Write::Bulk::Insert do
219
222
 
220
223
  context 'when write concern is acknowledged' do
221
224
 
222
- let(:write_concern) do
223
- Mongo::WriteConcern.get(w: 1)
224
- end
225
-
226
225
  context 'when the insert fails' do
227
226
 
228
227
  it 'does not abort after first error' do
229
- failing_insert.execute(authorized_primary.context)
228
+ failing_insert.execute(authorized_primary)
230
229
  expect(authorized_collection.find.count).to eq(2)
231
230
  end
232
231
  end
@@ -241,7 +240,7 @@ describe Mongo::Operation::Write::Bulk::Insert do
241
240
  context 'when the insert fails' do
242
241
 
243
242
  it 'does not after first error' do
244
- failing_insert.execute(authorized_primary.context)
243
+ failing_insert.execute(authorized_primary)
245
244
  expect(authorized_collection.find.count).to eq(2)
246
245
  end
247
246
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongo::Operation::Write::Bulk::Update do
4
- include_context 'operation'
5
4
 
6
5
  let(:documents) do
7
6
  [{ :q => { :foo => 1 },
@@ -12,13 +11,17 @@ describe Mongo::Operation::Write::Bulk::Update do
12
11
 
13
12
  let(:spec) do
14
13
  { updates: documents,
15
- db_name: db_name,
16
- coll_name: coll_name,
14
+ db_name: authorized_collection.database.name,
15
+ coll_name: authorized_collection.name,
17
16
  write_concern: write_concern,
18
17
  ordered: true
19
18
  }
20
19
  end
21
20
 
21
+ let(:write_concern) do
22
+ Mongo::WriteConcern.get(WRITE_CONCERN)
23
+ end
24
+
22
25
  let(:op) do
23
26
  described_class.new(spec)
24
27
  end
@@ -56,8 +59,8 @@ describe Mongo::Operation::Write::Bulk::Update do
56
59
 
57
60
  let(:other_spec) do
58
61
  { updates: other_docs,
59
- db_name: db_name,
60
- coll_name: coll_name,
62
+ db_name: authorized_collection.database.name,
63
+ coll_name: authorized_collection.name,
61
64
  write_concern: write_concern,
62
65
  ordered: true
63
66
  }
@@ -94,7 +97,7 @@ describe Mongo::Operation::Write::Bulk::Update do
94
97
  end
95
98
 
96
99
  it 'updates the document' do
97
- op.execute(authorized_primary.context)
100
+ op.execute(authorized_primary)
98
101
  expect(authorized_collection.find(field: 'blah').count).to eq(1)
99
102
  end
100
103
  end
@@ -105,8 +108,8 @@ describe Mongo::Operation::Write::Bulk::Update do
105
108
  let(:update) do
106
109
  described_class.new({
107
110
  updates: documents,
108
- db_name: db_name,
109
- coll_name: coll_name,
111
+ db_name: authorized_collection.database.name,
112
+ coll_name: authorized_collection.name,
110
113
  write_concern: write_concern
111
114
  })
112
115
  end
@@ -118,7 +121,7 @@ describe Mongo::Operation::Write::Bulk::Update do
118
121
  end
119
122
 
120
123
  it 'updates the documents' do
121
- op.execute(authorized_primary.context)
124
+ op.execute(authorized_primary)
122
125
  expect(authorized_collection.find(field: 'blah').count).to eq(2)
123
126
  end
124
127
  end
@@ -134,8 +137,8 @@ describe Mongo::Operation::Write::Bulk::Update do
134
137
 
135
138
  let(:spec) do
136
139
  { updates: documents,
137
- db_name: db_name,
138
- coll_name: coll_name,
140
+ db_name: authorized_collection.database.name,
141
+ coll_name: authorized_collection.name,
139
142
  write_concern: write_concern,
140
143
  ordered: true
141
144
  }
@@ -149,12 +152,8 @@ describe Mongo::Operation::Write::Bulk::Update do
149
152
 
150
153
  context 'when write concern is acknowledged' do
151
154
 
152
- let(:write_concern) do
153
- Mongo::WriteConcern.get(w: 1)
154
- end
155
-
156
155
  it 'aborts after first error' do
157
- failing_update.execute(authorized_primary.context)
156
+ failing_update.execute(authorized_primary)
158
157
  expect(authorized_collection.find(other: 'blah').count).to eq(0)
159
158
  end
160
159
  end
@@ -166,7 +165,7 @@ describe Mongo::Operation::Write::Bulk::Update do
166
165
  end
167
166
 
168
167
  it 'aborts after first error' do
169
- failing_update.execute(authorized_primary.context)
168
+ failing_update.execute(authorized_primary)
170
169
  expect(authorized_collection.find(other: 'blah').count).to eq(0)
171
170
  end
172
171
  end
@@ -183,8 +182,8 @@ describe Mongo::Operation::Write::Bulk::Update do
183
182
 
184
183
  let(:spec) do
185
184
  { updates: documents,
186
- db_name: db_name,
187
- coll_name: coll_name,
185
+ db_name: authorized_collection.database.name,
186
+ coll_name: authorized_collection.name,
188
187
  write_concern: write_concern,
189
188
  ordered: false
190
189
  }
@@ -198,12 +197,8 @@ describe Mongo::Operation::Write::Bulk::Update do
198
197
 
199
198
  context 'when write concern is acknowledged' do
200
199
 
201
- let(:write_concern) do
202
- Mongo::WriteConcern.get(w: 1)
203
- end
204
-
205
200
  it 'does not abort after first error' do
206
- failing_update.execute(authorized_primary.context)
201
+ failing_update.execute(authorized_primary)
207
202
  expect(authorized_collection.find(other: 'blah').count).to eq(1)
208
203
  end
209
204
  end
@@ -215,7 +210,7 @@ describe Mongo::Operation::Write::Bulk::Update do
215
210
  end
216
211
 
217
212
  it 'does not abort after first error' do
218
- failing_update.execute(authorized_primary.context)
213
+ failing_update.execute(authorized_primary)
219
214
  expect(authorized_collection.find(other: 'blah').count).to eq(1)
220
215
  end
221
216
  end
@@ -1,13 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongo::Operation::Write::Command::Delete do
4
- include_context 'operation'
4
+
5
+ let(:write_concern) do
6
+ Mongo::WriteConcern.get(WRITE_CONCERN)
7
+ end
5
8
 
6
9
  let(:deletes) { [{:q => { :foo => 1 }, :limit => 1}] }
7
10
  let(:spec) do
8
11
  { :deletes => deletes,
9
- :db_name => db_name,
10
- :coll_name => coll_name,
12
+ :db_name => authorized_collection.database.name,
13
+ :coll_name => authorized_collection.name,
11
14
  :write_concern => write_concern,
12
15
  :ordered => true
13
16
  }
@@ -41,9 +44,9 @@ describe Mongo::Operation::Write::Command::Delete do
41
44
  let(:other_deletes) { [{:q => { :bar => 1 }, :limit => 1}] }
42
45
  let(:other_spec) do
43
46
  { :deletes => other_deletes,
44
- :db_name => db_name,
45
- :coll_name => coll_name,
46
- :write_concern => write_concern.options,
47
+ :db_name => authorized_collection.database.name,
48
+ :coll_name => authorized_collection.name,
49
+ :write_concern => write_concern,
47
50
  :ordered => true
48
51
  }
49
52
  end
@@ -62,8 +65,8 @@ describe Mongo::Operation::Write::Command::Delete do
62
65
 
63
66
  let(:spec) do
64
67
  { :deletes => deletes,
65
- :db_name => db_name,
66
- :coll_name => coll_name,
68
+ :db_name => authorized_collection.database.name,
69
+ :coll_name => authorized_collection.name,
67
70
  :ordered => true
68
71
  }
69
72
  end
@@ -81,32 +84,23 @@ describe Mongo::Operation::Write::Command::Delete do
81
84
  end
82
85
  end
83
86
 
84
- describe '#execute' do
85
-
86
- context 'server' do
87
+ describe '#message' do
87
88
 
88
- context 'message' do
89
- let(:expected_selector) do
90
- { :deletes => deletes,
91
- :delete => coll_name,
92
- :writeConcern => write_concern.options,
93
- :ordered => true
94
- }
95
- end
89
+ let(:expected_selector) do
90
+ {
91
+ :delete => authorized_collection.name,
92
+ :deletes => deletes,
93
+ :writeConcern => write_concern.options,
94
+ :ordered => true
95
+ }
96
+ end
96
97
 
97
- it 'creates a query wire protocol message with correct specs' do
98
- allow_any_instance_of(Mongo::ServerSelector::Primary).to receive(:server) do
99
- primary_server
100
- end
101
-
102
- expect(Mongo::Protocol::Query).to receive(:new) do |db, coll, sel, options|
103
- expect(db).to eq(db_name)
104
- expect(coll).to eq(Mongo::Database::COMMAND)
105
- expect(sel).to eq(expected_selector)
106
- end
107
- op.execute(primary_context)
108
- end
109
- end
98
+ it 'creates the correct query wire protocol message' do
99
+ expect(Mongo::Protocol::Query).to receive(:new).with(authorized_collection.database.name,
100
+ '$cmd',
101
+ expected_selector,
102
+ { limit: -1 } )
103
+ op.send(:message)
110
104
  end
111
105
  end
112
106
  end
@@ -1,18 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongo::Operation::Write::Command::Insert do
4
- include_context 'operation'
5
4
 
6
5
  let(:documents) { [{ :_id => 1, :foo => 1 }] }
7
6
  let(:spec) do
8
7
  { :documents => documents,
9
- :db_name => db_name,
10
- :coll_name => coll_name,
8
+ :db_name => authorized_collection.database.name,
9
+ :coll_name => authorized_collection.name,
11
10
  :write_concern => write_concern,
12
11
  :ordered => true
13
12
  }
14
13
  end
15
14
 
15
+ let(:write_concern) do
16
+ Mongo::WriteConcern.get(WRITE_CONCERN)
17
+ end
18
+
16
19
  let(:op) { described_class.new(spec) }
17
20
 
18
21
  describe '#initialize' do
@@ -41,8 +44,8 @@ describe Mongo::Operation::Write::Command::Insert do
41
44
  let(:other_documents) { [{ :bar => 1 }] }
42
45
  let(:other_spec) do
43
46
  { :documents => other_documents,
44
- :db_name => db_name,
45
- :insert => coll_name,
47
+ :db_name => authorized_collection.database.name,
48
+ :insert => authorized_collection.name,
46
49
  :write_concern => write_concern.options,
47
50
  :ordered => true
48
51
  }
@@ -62,8 +65,8 @@ describe Mongo::Operation::Write::Command::Insert do
62
65
 
63
66
  let(:spec) do
64
67
  { :documents => documents,
65
- :db_name => db_name,
66
- :coll_name => coll_name,
68
+ :db_name => authorized_collection.database.name,
69
+ :coll_name => authorized_collection.name,
67
70
  :ordered => true
68
71
  }
69
72
  end
@@ -81,32 +84,22 @@ describe Mongo::Operation::Write::Command::Insert do
81
84
  end
82
85
  end
83
86
 
84
- describe '#execute' do
85
-
86
- context 'server' do
87
+ describe '#message' do
87
88
 
88
- context 'message' do
89
- let(:expected_selector) do
90
- { :documents => documents,
91
- :insert => coll_name,
92
- :writeConcern => write_concern.options,
93
- :ordered => true
94
- }
95
- end
89
+ let(:expected_selector) do
90
+ { :documents => documents,
91
+ :insert => authorized_collection.name,
92
+ :writeConcern => write_concern.options,
93
+ :ordered => true
94
+ }
95
+ end
96
96
 
97
- it 'creates a query wire protocol message with correct specs' do
98
- allow_any_instance_of(Mongo::ServerSelector::Primary).to receive(:server) do
99
- primary_server
100
- end
101
-
102
- expect(Mongo::Protocol::Query).to receive(:new) do |db, coll, sel, options|
103
- expect(db).to eq(db_name)
104
- expect(coll).to eq(Mongo::Database::COMMAND)
105
- expect(sel).to eq(expected_selector)
106
- end
107
- op.execute(primary_context)
108
- end
109
- end
97
+ it 'creates a query wire protocol message with correct specs' do
98
+ expect(Mongo::Protocol::Query).to receive(:new).with(authorized_collection.database.name,
99
+ '$cmd',
100
+ expected_selector,
101
+ { limit: -1, validating_keys: true })
102
+ op.send(:message)
110
103
  end
111
104
  end
112
105
  end
@@ -1,16 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mongo::Operation::Write::Command::Update do
4
- include_context 'operation'
5
4
 
6
5
  let(:updates) { [{:q => { :foo => 1 },
7
6
  :u => { :$set => { :bar => 1 } },
8
7
  :multi => true,
9
8
  :upsert => false }] }
9
+
10
+ let(:write_concern) do
11
+ Mongo::WriteConcern.get(WRITE_CONCERN)
12
+ end
13
+
10
14
  let(:spec) do
11
15
  { :updates => updates,
12
- :db_name => db_name,
13
- :coll_name => coll_name,
16
+ :db_name => TEST_DB,
17
+ :coll_name => TEST_COLL,
14
18
  :write_concern => write_concern,
15
19
  :ordered => true
16
20
  }
@@ -47,9 +51,9 @@ describe Mongo::Operation::Write::Command::Update do
47
51
  :upsert => false }] }
48
52
  let(:other_spec) do
49
53
  { :updates => other_updates,
50
- :db_name => db_name,
51
- :coll_name => coll_name,
52
- :write_concern => write_concern.options,
54
+ :db_name => TEST_DB,
55
+ :coll_name => TEST_COLL,
56
+ :write_concern => Mongo::WriteConcern.get(WRITE_CONCERN),
53
57
  :ordered => true
54
58
  }
55
59
  end
@@ -68,8 +72,8 @@ describe Mongo::Operation::Write::Command::Update do
68
72
 
69
73
  let(:spec) do
70
74
  { :updates => updates,
71
- :db_name => db_name,
72
- :coll_name => coll_name,
75
+ :db_name => TEST_DB,
76
+ :coll_name => TEST_COLL,
73
77
  :ordered => true
74
78
  }
75
79
  end
@@ -87,32 +91,20 @@ describe Mongo::Operation::Write::Command::Update do
87
91
  end
88
92
  end
89
93
 
90
- describe '#execute' do
94
+ describe '#message' do
91
95
 
92
- context 'server' do
93
-
94
- context 'message' do
95
- let(:expected_selector) do
96
- { :updates => updates,
97
- :update => coll_name,
98
- :writeConcern => write_concern.options,
99
- :ordered => true
100
- }
101
- end
96
+ let(:expected_selector) do
97
+ {
98
+ :update => TEST_COLL,
99
+ :updates => updates,
100
+ :ordered => true,
101
+ :writeConcern => write_concern.options
102
+ }
103
+ end
102
104
 
103
- it 'creates a query wire protocol message with correct specs' do
104
- allow_any_instance_of(Mongo::ServerSelector::Primary).to receive(:server) do
105
- primary_server
106
- end
107
-
108
- expect(Mongo::Protocol::Query).to receive(:new) do |db, coll, sel, options|
109
- expect(db).to eq(db_name)
110
- expect(coll).to eq(Mongo::Database::COMMAND)
111
- expect(sel).to eq(expected_selector)
112
- end
113
- op.execute(primary_context)
114
- end
115
- end
105
+ it 'creates the correct Command message' do
106
+ expect(Mongo::Protocol::Query).to receive(:new).with(TEST_DB, '$cmd', expected_selector, { limit: -1 })
107
+ op.send(:message)
116
108
  end
117
109
  end
118
110
  end