mongo 2.2.7 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/mongo.rb +1 -1
- data/lib/mongo/address.rb +1 -1
- data/lib/mongo/address/ipv4.rb +1 -1
- data/lib/mongo/address/ipv6.rb +1 -1
- data/lib/mongo/address/unix.rb +1 -1
- data/lib/mongo/auth.rb +1 -1
- data/lib/mongo/auth/cr.rb +1 -1
- data/lib/mongo/auth/ldap.rb +1 -1
- data/lib/mongo/auth/roles.rb +1 -1
- data/lib/mongo/auth/user.rb +1 -1
- data/lib/mongo/auth/user/view.rb +5 -5
- data/lib/mongo/auth/x509.rb +1 -1
- data/lib/mongo/bson.rb +1 -1
- data/lib/mongo/bulk_write.rb +4 -4
- data/lib/mongo/bulk_write/combineable.rb +1 -1
- data/lib/mongo/bulk_write/ordered_combiner.rb +1 -1
- data/lib/mongo/bulk_write/result.rb +1 -1
- data/lib/mongo/bulk_write/result_combiner.rb +1 -1
- data/lib/mongo/bulk_write/transformable.rb +1 -1
- data/lib/mongo/bulk_write/unordered_combiner.rb +1 -1
- data/lib/mongo/bulk_write/validatable.rb +1 -1
- data/lib/mongo/client.rb +2 -2
- data/lib/mongo/cluster.rb +15 -3
- data/lib/mongo/cluster/cursor_reaper.rb +174 -0
- data/lib/mongo/cluster/topology.rb +1 -1
- data/lib/mongo/cluster/topology/replica_set.rb +1 -1
- data/lib/mongo/cluster/topology/sharded.rb +1 -1
- data/lib/mongo/cluster/topology/single.rb +1 -1
- data/lib/mongo/cluster/topology/unknown.rb +1 -1
- data/lib/mongo/collection.rb +5 -4
- data/lib/mongo/collection/view.rb +4 -4
- data/lib/mongo/collection/view/aggregation.rb +2 -2
- data/lib/mongo/collection/view/builder.rb +1 -1
- data/lib/mongo/collection/view/builder/aggregation.rb +1 -1
- data/lib/mongo/collection/view/builder/find_command.rb +1 -1
- data/lib/mongo/collection/view/builder/flags.rb +1 -1
- data/lib/mongo/collection/view/builder/map_reduce.rb +1 -1
- data/lib/mongo/collection/view/builder/modifiers.rb +1 -1
- data/lib/mongo/collection/view/builder/op_query.rb +1 -1
- data/lib/mongo/collection/view/explainable.rb +1 -1
- data/lib/mongo/collection/view/immutable.rb +1 -1
- data/lib/mongo/collection/view/iterable.rb +2 -2
- data/lib/mongo/collection/view/map_reduce.rb +3 -3
- data/lib/mongo/collection/view/readable.rb +23 -6
- data/lib/mongo/collection/view/writable.rb +3 -3
- data/lib/mongo/cursor.rb +50 -7
- data/lib/mongo/cursor/builder.rb +1 -1
- data/lib/mongo/cursor/builder/get_more_command.rb +1 -1
- data/lib/mongo/cursor/builder/kill_cursors_command.rb +29 -1
- data/lib/mongo/cursor/builder/op_get_more.rb +1 -1
- data/lib/mongo/cursor/builder/op_kill_cursors.rb +29 -1
- data/lib/mongo/database.rb +4 -4
- data/lib/mongo/database/view.rb +2 -2
- data/lib/mongo/dbref.rb +4 -3
- data/lib/mongo/error.rb +1 -1
- data/lib/mongo/error/bulk_write_error.rb +1 -1
- data/lib/mongo/error/closed_stream.rb +1 -1
- data/lib/mongo/error/extra_file_chunk.rb +1 -1
- data/lib/mongo/error/file_not_found.rb +1 -1
- data/lib/mongo/error/invalid_bulk_operation.rb +1 -1
- data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -1
- data/lib/mongo/error/invalid_collection_name.rb +1 -1
- data/lib/mongo/error/invalid_database_name.rb +1 -1
- data/lib/mongo/error/invalid_document.rb +1 -1
- data/lib/mongo/error/invalid_file.rb +1 -1
- data/lib/mongo/error/invalid_file_revision.rb +1 -1
- data/lib/mongo/error/invalid_nonce.rb +1 -1
- data/lib/mongo/error/invalid_replacement_document.rb +1 -1
- data/lib/mongo/error/invalid_server_preference.rb +1 -1
- data/lib/mongo/error/invalid_signature.rb +1 -1
- data/lib/mongo/error/invalid_update_document.rb +1 -1
- data/lib/mongo/error/invalid_uri.rb +1 -1
- data/lib/mongo/error/invalid_write_concern.rb +1 -1
- data/lib/mongo/error/max_bson_size.rb +1 -1
- data/lib/mongo/error/max_message_size.rb +1 -1
- data/lib/mongo/error/missing_file_chunk.rb +1 -1
- data/lib/mongo/error/multi_index_drop.rb +1 -1
- data/lib/mongo/error/need_primary_server.rb +1 -1
- data/lib/mongo/error/no_server_available.rb +4 -2
- data/lib/mongo/error/operation_failure.rb +1 -1
- data/lib/mongo/error/parser.rb +1 -1
- data/lib/mongo/error/socket_error.rb +1 -1
- data/lib/mongo/error/socket_timeout_error.rb +1 -1
- data/lib/mongo/error/unchangeable_collection_option.rb +1 -1
- data/lib/mongo/error/unexpected_chunk_length.rb +1 -1
- data/lib/mongo/error/unexpected_response.rb +1 -1
- data/lib/mongo/error/unsupported_features.rb +1 -1
- data/lib/mongo/event.rb +1 -1
- data/lib/mongo/event/description_changed.rb +1 -1
- data/lib/mongo/event/publisher.rb +1 -1
- data/lib/mongo/event/subscriber.rb +1 -1
- data/lib/mongo/grid.rb +1 -1
- data/lib/mongo/grid/file.rb +6 -2
- data/lib/mongo/grid/file/chunk.rb +6 -4
- data/lib/mongo/grid/file/info.rb +7 -3
- data/lib/mongo/grid/fs_bucket.rb +12 -6
- data/lib/mongo/grid/stream.rb +1 -1
- data/lib/mongo/grid/stream/read.rb +2 -4
- data/lib/mongo/grid/stream/write.rb +4 -3
- data/lib/mongo/index.rb +1 -1
- data/lib/mongo/index/view.rb +5 -4
- data/lib/mongo/loggable.rb +1 -1
- data/lib/mongo/logger.rb +1 -1
- data/lib/mongo/monitoring.rb +1 -1
- data/lib/mongo/operation.rb +1 -1
- data/lib/mongo/operation/commands.rb +1 -1
- data/lib/mongo/operation/commands/aggregate.rb +7 -7
- data/lib/mongo/operation/commands/aggregate/result.rb +1 -1
- data/lib/mongo/operation/commands/collections_info.rb +10 -9
- data/lib/mongo/operation/commands/collections_info/result.rb +1 -1
- data/lib/mongo/operation/commands/command.rb +1 -1
- data/lib/mongo/operation/commands/indexes.rb +12 -11
- data/lib/mongo/operation/commands/list_collections.rb +1 -1
- data/lib/mongo/operation/commands/list_collections/result.rb +1 -1
- data/lib/mongo/operation/commands/list_indexes.rb +1 -1
- data/lib/mongo/operation/commands/list_indexes/result.rb +1 -1
- data/lib/mongo/operation/commands/map_reduce.rb +1 -1
- data/lib/mongo/operation/commands/map_reduce/result.rb +1 -1
- data/lib/mongo/operation/commands/user_query.rb +11 -10
- data/lib/mongo/operation/commands/users_info.rb +2 -2
- data/lib/mongo/operation/commands/users_info/result.rb +1 -1
- data/lib/mongo/operation/executable.rb +8 -7
- data/lib/mongo/operation/kill_cursors.rb +2 -2
- data/lib/mongo/operation/limited.rb +1 -1
- data/lib/mongo/operation/read.rb +1 -1
- data/lib/mongo/operation/read/get_more.rb +2 -2
- data/lib/mongo/operation/read/query.rb +1 -1
- data/lib/mongo/operation/read/query/result.rb +1 -1
- data/lib/mongo/operation/read_preference.rb +10 -10
- data/lib/mongo/operation/result.rb +1 -1
- data/lib/mongo/operation/specifiable.rb +2 -2
- data/lib/mongo/operation/write.rb +1 -1
- data/lib/mongo/operation/write/bulk.rb +1 -1
- data/lib/mongo/operation/write/bulk/bulkable.rb +9 -9
- data/lib/mongo/operation/write/bulk/delete.rb +3 -3
- data/lib/mongo/operation/write/bulk/delete/result.rb +1 -1
- data/lib/mongo/operation/write/bulk/insert.rb +5 -5
- data/lib/mongo/operation/write/bulk/insert/result.rb +1 -1
- data/lib/mongo/operation/write/bulk/legacy_mergable.rb +1 -1
- data/lib/mongo/operation/write/bulk/mergable.rb +1 -1
- data/lib/mongo/operation/write/bulk/update.rb +3 -3
- data/lib/mongo/operation/write/bulk/update/result.rb +1 -1
- data/lib/mongo/operation/write/command.rb +1 -1
- data/lib/mongo/operation/write/command/create_index.rb +1 -1
- data/lib/mongo/operation/write/command/create_user.rb +1 -1
- data/lib/mongo/operation/write/command/delete.rb +1 -1
- data/lib/mongo/operation/write/command/drop_index.rb +1 -1
- data/lib/mongo/operation/write/command/insert.rb +11 -1
- data/lib/mongo/operation/write/command/remove_user.rb +1 -1
- data/lib/mongo/operation/write/command/update.rb +1 -1
- data/lib/mongo/operation/write/command/update_user.rb +1 -1
- data/lib/mongo/operation/write/command/writable.rb +7 -6
- data/lib/mongo/operation/write/create_index.rb +1 -1
- data/lib/mongo/operation/write/create_user.rb +1 -1
- data/lib/mongo/operation/write/delete.rb +1 -1
- data/lib/mongo/operation/write/delete/result.rb +1 -1
- data/lib/mongo/operation/write/drop_index.rb +5 -5
- data/lib/mongo/operation/write/gle.rb +3 -3
- data/lib/mongo/operation/write/idable.rb +1 -1
- data/lib/mongo/operation/write/insert.rb +5 -5
- data/lib/mongo/operation/write/insert/result.rb +1 -1
- data/lib/mongo/operation/write/remove_user.rb +1 -1
- data/lib/mongo/operation/write/update.rb +1 -1
- data/lib/mongo/operation/write/update/result.rb +1 -1
- data/lib/mongo/operation/write/update_user.rb +1 -1
- data/lib/mongo/operation/write/write_command_enabled.rb +10 -9
- data/lib/mongo/protocol/bit_vector.rb +2 -2
- data/lib/mongo/protocol/delete.rb +1 -1
- data/lib/mongo/protocol/get_more.rb +1 -1
- data/lib/mongo/protocol/insert.rb +5 -1
- data/lib/mongo/protocol/kill_cursors.rb +1 -1
- data/lib/mongo/protocol/message.rb +9 -5
- data/lib/mongo/protocol/query.rb +1 -1
- data/lib/mongo/protocol/reply.rb +1 -1
- data/lib/mongo/protocol/serializers.rb +8 -8
- data/lib/mongo/protocol/update.rb +1 -1
- data/lib/mongo/server.rb +40 -3
- data/lib/mongo/server/connectable.rb +1 -1
- data/lib/mongo/server/connection.rb +4 -2
- data/lib/mongo/server/connection_pool.rb +1 -1
- data/lib/mongo/server/connection_pool/queue.rb +1 -1
- data/lib/mongo/server/context.rb +3 -1
- data/lib/mongo/server/description.rb +1 -1
- data/lib/mongo/server/description/inspector/description_changed.rb +1 -1
- data/lib/mongo/server/monitor.rb +1 -1
- data/lib/mongo/server_selector.rb +2 -1
- data/lib/mongo/server_selector/nearest.rb +1 -1
- data/lib/mongo/server_selector/primary.rb +1 -1
- data/lib/mongo/server_selector/primary_preferred.rb +1 -1
- data/lib/mongo/server_selector/secondary.rb +1 -1
- data/lib/mongo/server_selector/secondary_preferred.rb +1 -1
- data/lib/mongo/server_selector/selectable.rb +12 -7
- data/lib/mongo/socket.rb +1 -1
- data/lib/mongo/socket/ssl.rb +1 -1
- data/lib/mongo/socket/tcp.rb +1 -1
- data/lib/mongo/socket/unix.rb +1 -1
- data/lib/mongo/uri.rb +1 -1
- data/lib/mongo/version.rb +2 -2
- data/lib/mongo/write_concern/acknowledged.rb +1 -1
- data/lib/mongo/write_concern/normalizable.rb +1 -1
- data/lib/mongo/write_concern/unacknowledged.rb +1 -1
- data/mongo.gemspec +1 -1
- data/spec/mongo/client_spec.rb +2 -2
- data/spec/mongo/cluster/cursor_reaper_spec.rb +216 -0
- data/spec/mongo/cluster_spec.rb +36 -5
- data/spec/mongo/collection/view/aggregation_spec.rb +2 -2
- data/spec/mongo/collection/view/map_reduce_spec.rb +2 -2
- data/spec/mongo/collection/view/readable_spec.rb +203 -5
- data/spec/mongo/collection/view_spec.rb +10 -0
- data/spec/mongo/collection_spec.rb +64 -18
- data/spec/mongo/cursor_spec.rb +89 -0
- data/spec/mongo/database_spec.rb +79 -13
- data/spec/mongo/grid/fs_bucket_spec.rb +119 -1
- data/spec/mongo/grid/stream/write_spec.rb +63 -12
- data/spec/mongo/index/view_spec.rb +19 -0
- data/spec/mongo/operation/commands/aggregate_spec.rb +10 -7
- data/spec/mongo/operation/commands/collections_info_spec.rb +1 -1
- data/spec/mongo/operation/commands/command_spec.rb +3 -3
- data/spec/mongo/operation/commands/indexes_spec.rb +1 -1
- data/spec/mongo/operation/commands/map_reduce_spec.rb +2 -2
- data/spec/mongo/operation/kill_cursors_spec.rb +10 -19
- data/spec/mongo/operation/read/get_more_spec.rb +13 -25
- data/spec/mongo/operation/read/query_spec.rb +26 -30
- data/spec/mongo/operation/read_preference_spec.rb +11 -11
- data/spec/mongo/operation/specifiable_spec.rb +31 -0
- data/spec/mongo/operation/write/bulk/delete_spec.rb +16 -18
- data/spec/mongo/operation/write/bulk/insert_spec.rb +17 -18
- data/spec/mongo/operation/write/bulk/update_spec.rb +20 -25
- data/spec/mongo/operation/write/command/delete_spec.rb +26 -32
- data/spec/mongo/operation/write/command/insert_spec.rb +24 -31
- data/spec/mongo/operation/write/command/update_spec.rb +24 -32
- data/spec/mongo/operation/write/create_index_spec.rb +4 -4
- data/spec/mongo/operation/write/create_user_spec.rb +3 -3
- data/spec/mongo/operation/write/delete_spec.rb +51 -22
- data/spec/mongo/operation/write/drop_index_spec.rb +2 -2
- data/spec/mongo/operation/write/insert_spec.rb +42 -11
- data/spec/mongo/operation/write/remove_user_spec.rb +4 -4
- data/spec/mongo/operation/write/update_spec.rb +34 -6
- data/spec/mongo/operation/write/update_user_spec.rb +1 -1
- data/spec/mongo/server/connection_spec.rb +22 -14
- data/spec/mongo/server_selection_spec.rb +2 -2
- data/spec/mongo/server_selector/nearest_spec.rb +4 -4
- data/spec/mongo/server_selector/primary_preferred_spec.rb +4 -4
- data/spec/mongo/server_selector/primary_spec.rb +2 -2
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +4 -4
- data/spec/mongo/server_selector/secondary_spec.rb +3 -3
- data/spec/mongo/server_selector_spec.rb +82 -3
- data/spec/mongo/server_spec.rb +0 -20
- data/spec/support/command_monitoring.rb +1 -1
- data/spec/support/connection_string.rb +1 -1
- data/spec/support/crud.rb +1 -1
- data/spec/support/crud/read.rb +1 -1
- data/spec/support/crud/write.rb +1 -1
- data/spec/support/gridfs.rb +1 -1
- data/spec/support/shared/server_selector.rb +3 -3
- metadata +7 -10
- metadata.gz.sig +0 -0
- data/lib/csasl/csasl.bundle +0 -0
- data/spec/mongo/operation/write/response_spec.rb +0 -85
- data/spec/support/shared/operation.rb +0 -100
data/spec/mongo/database_spec.rb
CHANGED
@@ -63,6 +63,25 @@ describe Mongo::Database do
|
|
63
63
|
end.to raise_error(Mongo::Error::InvalidCollectionName)
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
context 'when the client has options' do
|
68
|
+
|
69
|
+
let(:client) do
|
70
|
+
Mongo::Client.new([default_address.host], read: { mode: :secondary })
|
71
|
+
end
|
72
|
+
|
73
|
+
let(:database) do
|
74
|
+
client.database
|
75
|
+
end
|
76
|
+
|
77
|
+
let(:collection) do
|
78
|
+
database[:with_read_pref]
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'applies the options to the collection' do
|
82
|
+
expect(collection.read_preference).to eq(Mongo::ServerSelector.get(mode: :secondary))
|
83
|
+
end
|
84
|
+
end
|
66
85
|
end
|
67
86
|
|
68
87
|
describe '#collection_names' do
|
@@ -225,40 +244,87 @@ describe Mongo::Database do
|
|
225
244
|
end
|
226
245
|
end
|
227
246
|
|
228
|
-
context 'when
|
247
|
+
context 'when no read preference is provided', unless: sharded? do
|
248
|
+
|
249
|
+
let!(:primary_server) do
|
250
|
+
database.cluster.next_primary
|
251
|
+
end
|
229
252
|
|
230
253
|
before do
|
231
|
-
|
254
|
+
expect(primary_server).to receive(:with_connection).at_least(:once).and_call_original
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'uses read preference of primary' do
|
258
|
+
expect(database.command(ping: 1)).to be_successful
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'when the client has a read preference set', unless: sharded? do
|
263
|
+
|
264
|
+
let!(:primary_server) do
|
265
|
+
database.cluster.next_primary
|
232
266
|
end
|
233
267
|
|
234
|
-
let(:
|
268
|
+
let(:read_preference) do
|
235
269
|
{ :mode => :secondary, :tag_sets => [{ 'non' => 'existent' }] }
|
236
270
|
end
|
237
271
|
|
238
272
|
let(:client) do
|
239
|
-
authorized_client.with(
|
273
|
+
authorized_client.with(read: read_preference)
|
240
274
|
end
|
241
275
|
|
242
276
|
let(:database) do
|
243
277
|
described_class.new(client, TEST_DB, client.options)
|
244
278
|
end
|
245
279
|
|
246
|
-
|
247
|
-
expect
|
248
|
-
|
249
|
-
|
280
|
+
before do
|
281
|
+
expect(primary_server).to receive(:with_connection).at_least(:once).and_call_original
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'does not use the client read preference 'do
|
285
|
+
expect(database.command(ping: 1)).to be_successful
|
250
286
|
end
|
251
287
|
end
|
252
288
|
|
253
|
-
context 'when there is a read preference
|
289
|
+
context 'when there is a read preference argument provided', unless: sharded? do
|
290
|
+
|
291
|
+
let(:read_preference) do
|
292
|
+
{ :mode => :secondary, :tag_sets => [{ 'non' => 'existent' }] }
|
293
|
+
end
|
294
|
+
|
295
|
+
let(:client) do
|
296
|
+
authorized_client.with(server_selection_timeout: 0.2)
|
297
|
+
end
|
254
298
|
|
255
299
|
let(:database) do
|
256
|
-
described_class.new(
|
300
|
+
described_class.new(client, TEST_DB, client.options)
|
301
|
+
end
|
302
|
+
|
303
|
+
before do
|
304
|
+
allow(database.cluster).to receive(:single?).and_return(false)
|
257
305
|
end
|
258
306
|
|
259
|
-
it '
|
260
|
-
expect
|
261
|
-
|
307
|
+
it 'uses the read preference argument' do
|
308
|
+
expect {
|
309
|
+
database.command({ ping: 1 }, read: read_preference)
|
310
|
+
}.to raise_error(Mongo::Error::NoServerAvailable)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
context 'when the client has a server_selection_timeout set', unless: sharded? do
|
315
|
+
|
316
|
+
let(:client) do
|
317
|
+
authorized_client.with(server_selection_timeout: 0)
|
318
|
+
end
|
319
|
+
|
320
|
+
let(:database) do
|
321
|
+
described_class.new(client, TEST_DB, client.options)
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'uses the client server_selection_timeout' do
|
325
|
+
expect {
|
326
|
+
database.command(ping: 1)
|
327
|
+
}.to raise_error(Mongo::Error::NoServerAvailable)
|
262
328
|
end
|
263
329
|
end
|
264
330
|
end
|
@@ -51,7 +51,7 @@ describe Mongo::Grid::FSBucket do
|
|
51
51
|
context 'when a read preference is set' do
|
52
52
|
|
53
53
|
let(:options) do
|
54
|
-
{ read: { mode: :secondary
|
54
|
+
{ read: { mode: :secondary } }
|
55
55
|
end
|
56
56
|
|
57
57
|
let(:read_pref) do
|
@@ -63,6 +63,21 @@ describe Mongo::Grid::FSBucket do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
context 'when a read preference is not set' do
|
67
|
+
|
68
|
+
let(:database) do
|
69
|
+
authorized_client.with(read: { mode: :secondary }).database
|
70
|
+
end
|
71
|
+
|
72
|
+
let(:fs) do
|
73
|
+
described_class.new(database, options)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'uses the read preference of the database' do
|
77
|
+
expect(fs.read_preference).to be(database.read_preference)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
66
81
|
context 'when a write stream is opened' do
|
67
82
|
|
68
83
|
let(:stream) do
|
@@ -221,9 +236,22 @@ describe Mongo::Grid::FSBucket do
|
|
221
236
|
fs.find_one(:filename => 'test.txt')
|
222
237
|
end
|
223
238
|
|
239
|
+
let(:from_db_upload_date) do
|
240
|
+
from_db.info.upload_date.strftime("%Y-%m-%d %H:%M:%S")
|
241
|
+
end
|
242
|
+
|
243
|
+
let(:file_info_upload_date) do
|
244
|
+
file.info.upload_date.strftime("%Y-%m-%d %H:%M:%S")
|
245
|
+
end
|
246
|
+
|
224
247
|
it 'returns the assembled file from the db' do
|
225
248
|
expect(from_db.filename).to eq(file.info.filename)
|
226
249
|
end
|
250
|
+
|
251
|
+
it 'maps the file info correctly' do
|
252
|
+
expect(from_db.info.length).to eq(file.info.length)
|
253
|
+
expect(from_db_upload_date).to eq(file_info_upload_date)
|
254
|
+
end
|
227
255
|
end
|
228
256
|
|
229
257
|
describe '#insert_one' do
|
@@ -434,6 +462,25 @@ describe Mongo::Grid::FSBucket do
|
|
434
462
|
it 'removes the file from the db' do
|
435
463
|
expect(from_db).to be_nil
|
436
464
|
end
|
465
|
+
|
466
|
+
context 'when a custom file id is used' do
|
467
|
+
|
468
|
+
let(:custom_file_id) do
|
469
|
+
fs.upload_from_stream(filename, file, file_id: 'Custom ID')
|
470
|
+
end
|
471
|
+
|
472
|
+
before do
|
473
|
+
fs.delete(custom_file_id)
|
474
|
+
end
|
475
|
+
|
476
|
+
let(:from_db) do
|
477
|
+
fs.find_one(:filename => filename)
|
478
|
+
end
|
479
|
+
|
480
|
+
it 'removes the file from the db' do
|
481
|
+
expect(from_db).to be_nil
|
482
|
+
end
|
483
|
+
end
|
437
484
|
end
|
438
485
|
|
439
486
|
context 'when a read stream is opened' do
|
@@ -498,6 +545,51 @@ describe Mongo::Grid::FSBucket do
|
|
498
545
|
expect(io.size).to eq(0)
|
499
546
|
end
|
500
547
|
end
|
548
|
+
|
549
|
+
context 'when a custom file id is provided' do
|
550
|
+
|
551
|
+
let(:file) do
|
552
|
+
File.open(__FILE__)
|
553
|
+
end
|
554
|
+
|
555
|
+
let!(:file_id) do
|
556
|
+
fs.open_upload_stream(filename, file_id: 'Custom ID') do |stream|
|
557
|
+
stream.write(file)
|
558
|
+
end.file_id
|
559
|
+
end
|
560
|
+
|
561
|
+
context 'when a block is provided' do
|
562
|
+
|
563
|
+
let!(:stream) do
|
564
|
+
fs.open_download_stream(file_id) do |stream|
|
565
|
+
io.write(stream.read)
|
566
|
+
end
|
567
|
+
end
|
568
|
+
|
569
|
+
it 'yields the stream to the block' do
|
570
|
+
expect(io.size).to eq(file.size)
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
context 'when a block is not provided' do
|
575
|
+
|
576
|
+
let!(:stream) do
|
577
|
+
fs.open_download_stream(file_id)
|
578
|
+
end
|
579
|
+
|
580
|
+
it 'returns a Stream::Read object' do
|
581
|
+
expect(stream).to be_a(Mongo::Grid::FSBucket::Stream::Read)
|
582
|
+
end
|
583
|
+
|
584
|
+
it 'does not close the stream' do
|
585
|
+
expect(stream.closed?).to be(false)
|
586
|
+
end
|
587
|
+
|
588
|
+
it 'does not yield the stream to the block' do
|
589
|
+
expect(io.size).to eq(0)
|
590
|
+
end
|
591
|
+
end
|
592
|
+
end
|
501
593
|
end
|
502
594
|
|
503
595
|
describe '#download_to_stream' do
|
@@ -830,6 +922,21 @@ describe Mongo::Grid::FSBucket do
|
|
830
922
|
it 'creates an ObjectId for the file' do
|
831
923
|
expect(stream.file_id).to be_a(BSON::ObjectId)
|
832
924
|
end
|
925
|
+
|
926
|
+
context 'when a custom file ID is provided' do
|
927
|
+
|
928
|
+
let(:stream) do
|
929
|
+
fs.open_upload_stream(filename, file_id: 'Custom ID')
|
930
|
+
end
|
931
|
+
|
932
|
+
it 'returns a Stream::Write object' do
|
933
|
+
expect(stream).to be_a(Mongo::Grid::FSBucket::Stream::Write)
|
934
|
+
end
|
935
|
+
|
936
|
+
it 'creates an ObjectId for the file' do
|
937
|
+
expect(stream.file_id).to eq('Custom ID')
|
938
|
+
end
|
939
|
+
end
|
833
940
|
end
|
834
941
|
|
835
942
|
context 'when a block is provided' do
|
@@ -930,6 +1037,17 @@ describe Mongo::Grid::FSBucket do
|
|
930
1037
|
fs.open_upload_stream(filename, stream_options)
|
931
1038
|
end
|
932
1039
|
|
1040
|
+
context 'when a custom file id is provided' do
|
1041
|
+
|
1042
|
+
let(:stream_options) do
|
1043
|
+
{ file_id: 'Custom ID' }
|
1044
|
+
end
|
1045
|
+
|
1046
|
+
it 'sets the file id on the stream' do
|
1047
|
+
expect(stream.file_id).to eq('Custom ID')
|
1048
|
+
end
|
1049
|
+
end
|
1050
|
+
|
933
1051
|
context 'when a write option is specified' do
|
934
1052
|
|
935
1053
|
let(:stream_options) do
|
@@ -83,7 +83,7 @@ describe Mongo::Grid::FSBucket::Stream::Write do
|
|
83
83
|
|
84
84
|
let(:extra_options) do
|
85
85
|
{
|
86
|
-
|
86
|
+
write: { w: (WRITE_CONCERN[:w] + 1) }
|
87
87
|
}
|
88
88
|
end
|
89
89
|
|
@@ -174,6 +174,19 @@ describe Mongo::Grid::FSBucket::Stream::Write do
|
|
174
174
|
expect(stream.send(:file_info).document[:aliases]).to eq(options[:aliases])
|
175
175
|
end
|
176
176
|
end
|
177
|
+
|
178
|
+
context 'when provided a file_id option' do
|
179
|
+
|
180
|
+
let(:options) do
|
181
|
+
{
|
182
|
+
file_id: 'Custom ID'
|
183
|
+
}
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'assigns the stream the file id' do
|
187
|
+
expect(stream.file_id).to eq(options[:file_id])
|
188
|
+
end
|
189
|
+
end
|
177
190
|
end
|
178
191
|
end
|
179
192
|
|
@@ -285,25 +298,63 @@ describe Mongo::Grid::FSBucket::Stream::Write do
|
|
285
298
|
|
286
299
|
context 'when provided an io stream' do
|
287
300
|
|
288
|
-
|
289
|
-
stream.write(file)
|
290
|
-
stream.close
|
291
|
-
end
|
301
|
+
context 'when no file id is specified' do
|
292
302
|
|
293
|
-
|
294
|
-
|
295
|
-
|
303
|
+
before do
|
304
|
+
stream.write(file)
|
305
|
+
stream.close
|
306
|
+
end
|
296
307
|
|
297
|
-
|
298
|
-
|
308
|
+
it 'writes the contents of the stream' do
|
309
|
+
expect(file_from_db.data.size).to eq(file.size)
|
310
|
+
end
|
311
|
+
|
312
|
+
it 'updates the length written' do
|
313
|
+
expect(stream.send(:file_info).document['length']).to eq(file.size)
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'updates the position (n)' do
|
317
|
+
expect(stream.instance_variable_get(:@n)).to eq(1)
|
318
|
+
end
|
299
319
|
end
|
300
320
|
|
301
|
-
|
302
|
-
|
321
|
+
context 'when a custom file id is provided' do
|
322
|
+
|
323
|
+
let(:extra_options) do
|
324
|
+
{
|
325
|
+
file_id: 'Custom ID'
|
326
|
+
}
|
327
|
+
end
|
328
|
+
|
329
|
+
let!(:id) do
|
330
|
+
stream.write(file)
|
331
|
+
stream.close
|
332
|
+
end
|
333
|
+
|
334
|
+
it 'writes the contents of the stream' do
|
335
|
+
expect(file_from_db.data.size).to eq(file.size)
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'updates the length written' do
|
339
|
+
expect(stream.send(:file_info).document['length']).to eq(file.size)
|
340
|
+
end
|
341
|
+
|
342
|
+
it 'updates the position (n)' do
|
343
|
+
expect(stream.instance_variable_get(:@n)).to eq(1)
|
344
|
+
end
|
345
|
+
|
346
|
+
it 'uses the custom file id' do
|
347
|
+
expect(id).to eq(options[:file_id])
|
348
|
+
end
|
303
349
|
end
|
304
350
|
|
305
351
|
context 'when the user file contains no data' do
|
306
352
|
|
353
|
+
before do
|
354
|
+
stream.write(file)
|
355
|
+
stream.close
|
356
|
+
end
|
357
|
+
|
307
358
|
let(:file) do
|
308
359
|
StringIO.new('')
|
309
360
|
end
|
@@ -366,6 +366,25 @@ describe Mongo::Index::View do
|
|
366
366
|
it 'maps the ruby options to the server options' do
|
367
367
|
expect(models).to eq([ expected ])
|
368
368
|
end
|
369
|
+
|
370
|
+
context 'when using alternate names' do
|
371
|
+
|
372
|
+
let(:extended_options) do
|
373
|
+
options.merge!(expire_after_seconds: 5)
|
374
|
+
end
|
375
|
+
|
376
|
+
let(:extended_expected) do
|
377
|
+
expected.tap { |exp| exp[:expireAfterSeconds] = 5 }
|
378
|
+
end
|
379
|
+
|
380
|
+
let(:models) do
|
381
|
+
view.send(:normalize_models, [ extended_options ])
|
382
|
+
end
|
383
|
+
|
384
|
+
it 'maps the ruby options to the server options' do
|
385
|
+
expect(models).to eq([ extended_expected ])
|
386
|
+
end
|
387
|
+
end
|
369
388
|
end
|
370
389
|
end
|
371
390
|
end
|
@@ -1,17 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mongo::Operation::Commands::Aggregate do
|
4
|
-
|
4
|
+
|
5
|
+
let(:options) do
|
6
|
+
{}
|
7
|
+
end
|
5
8
|
|
6
9
|
let(:selector) do
|
7
|
-
{ :aggregate =>
|
10
|
+
{ :aggregate => TEST_COLL,
|
8
11
|
:pipeline => [],
|
9
12
|
}
|
10
13
|
end
|
11
14
|
let(:spec) do
|
12
15
|
{ :selector => selector,
|
13
|
-
:options =>
|
14
|
-
:db_name =>
|
16
|
+
:options => options,
|
17
|
+
:db_name => TEST_DB
|
15
18
|
}
|
16
19
|
end
|
17
20
|
let(:op) { described_class.new(spec) }
|
@@ -38,7 +41,7 @@ describe Mongo::Operation::Commands::Aggregate do
|
|
38
41
|
let(:other_spec) do
|
39
42
|
{ :selector => other_selector,
|
40
43
|
:options => options,
|
41
|
-
:db_name =>
|
44
|
+
:db_name => TEST_DB,
|
42
45
|
}
|
43
46
|
end
|
44
47
|
let(:other) { described_class.new(other_spec) }
|
@@ -54,14 +57,14 @@ describe Mongo::Operation::Commands::Aggregate do
|
|
54
57
|
context 'when the aggregation fails' do
|
55
58
|
|
56
59
|
let(:selector) do
|
57
|
-
{ :aggregate =>
|
60
|
+
{ :aggregate => TEST_COLL,
|
58
61
|
:pipeline => [{ '$invalid' => 'operator' }],
|
59
62
|
}
|
60
63
|
end
|
61
64
|
|
62
65
|
it 'raises an exception' do
|
63
66
|
expect {
|
64
|
-
op.execute(authorized_primary
|
67
|
+
op.execute(authorized_primary)
|
65
68
|
}.to raise_error(Mongo::Error::OperationFailure)
|
66
69
|
end
|
67
70
|
end
|