mongo 2.1.0.beta → 2.2.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/README.md +10 -3
- data/Rakefile +1 -7
- data/lib/mongo/address/ipv4.rb +6 -1
- data/lib/mongo/address/unix.rb +2 -2
- data/lib/mongo/address.rb +32 -10
- data/lib/mongo/auth/cr/conversation.rb +1 -1
- data/lib/mongo/auth/ldap/conversation.rb +7 -3
- data/lib/mongo/auth/scram/conversation.rb +9 -3
- data/lib/mongo/auth/user/view.rb +23 -2
- data/lib/mongo/auth/x509/conversation.rb +1 -1
- data/lib/mongo/bulk_write/combineable.rb +51 -0
- data/lib/mongo/bulk_write/ordered_combiner.rb +55 -0
- data/lib/mongo/bulk_write/result.rb +61 -8
- data/lib/mongo/bulk_write/result_combiner.rb +117 -0
- data/lib/mongo/bulk_write/transformable.rb +132 -0
- data/lib/mongo/bulk_write/unordered_combiner.rb +52 -0
- data/lib/mongo/bulk_write/validatable.rb +62 -0
- data/lib/mongo/bulk_write.rb +164 -23
- data/lib/mongo/client.rb +75 -18
- data/lib/mongo/cluster/topology/replica_set.rb +8 -6
- data/lib/mongo/cluster/topology/unknown.rb +5 -2
- data/lib/mongo/cluster.rb +85 -5
- data/lib/mongo/collection/view/aggregation.rb +19 -45
- data/lib/mongo/collection/view/builder/aggregation.rb +98 -0
- data/lib/mongo/collection/view/builder/find_command.rb +111 -0
- data/lib/mongo/collection/view/builder/flags.rb +62 -0
- data/lib/mongo/collection/view/builder/map_reduce.rb +134 -0
- data/lib/mongo/collection/view/builder/modifiers.rb +80 -0
- data/lib/mongo/collection/view/builder/op_query.rb +83 -0
- data/lib/mongo/collection/view/builder.rb +20 -0
- data/lib/mongo/collection/view/explainable.rb +15 -0
- data/lib/mongo/collection/view/immutable.rb +4 -11
- data/lib/mongo/collection/view/iterable.rb +40 -5
- data/lib/mongo/collection/view/map_reduce.rb +67 -37
- data/lib/mongo/collection/view/readable.rb +114 -100
- data/lib/mongo/collection/view/writable.rb +46 -22
- data/lib/mongo/collection/view.rb +25 -22
- data/lib/mongo/collection.rb +130 -12
- data/lib/mongo/cursor/builder/get_more_command.rb +71 -0
- data/lib/mongo/cursor/builder/kill_cursors_command.rb +62 -0
- data/lib/mongo/cursor/builder/op_get_more.rb +61 -0
- data/lib/mongo/cursor/builder/op_kill_cursors.rb +56 -0
- data/lib/mongo/cursor/builder.rb +18 -0
- data/lib/mongo/cursor.rb +76 -21
- data/lib/mongo/database/view.rb +11 -6
- data/lib/mongo/database.rb +16 -6
- data/lib/mongo/dbref.rb +9 -9
- data/lib/mongo/{bulk_write/unordered_bulk_write.rb → error/closed_stream.rb} +12 -21
- data/lib/mongo/{bulk_write/ordered_bulk_write.rb → error/extra_file_chunk.rb} +13 -27
- data/lib/mongo/error/file_not_found.rb +37 -0
- data/lib/mongo/error/invalid_file.rb +2 -2
- data/lib/mongo/error/invalid_file_revision.rb +37 -0
- data/lib/mongo/error/invalid_uri.rb +5 -4
- data/lib/mongo/error/invalid_write_concern.rb +35 -0
- data/lib/mongo/error/missing_file_chunk.rb +38 -0
- data/lib/mongo/error/operation_failure.rb +33 -2
- data/lib/mongo/error/unchangeable_collection_option.rb +38 -0
- data/lib/mongo/error/unexpected_chunk_length.rb +39 -0
- data/lib/mongo/error.rb +8 -0
- data/lib/mongo/grid/file/chunk.rb +9 -9
- data/lib/mongo/grid/file/{metadata.rb → info.rb} +41 -39
- data/lib/mongo/grid/file.rb +12 -9
- data/lib/mongo/grid/fs_bucket.rb +448 -0
- data/lib/mongo/grid/stream/read.rb +208 -0
- data/lib/mongo/grid/stream/write.rb +187 -0
- data/lib/mongo/grid/stream.rb +64 -0
- data/lib/mongo/grid.rb +2 -1
- data/lib/mongo/index/view.rb +7 -4
- data/lib/mongo/index.rb +5 -0
- data/lib/mongo/loggable.rb +34 -57
- data/lib/mongo/logger.rb +16 -78
- data/lib/mongo/monitoring/command_log_subscriber.rb +38 -14
- data/lib/mongo/monitoring/event/command_started.rb +2 -1
- data/lib/mongo/monitoring/event/command_succeeded.rb +24 -2
- data/lib/mongo/monitoring/event/secure.rb +58 -0
- data/lib/mongo/monitoring/event.rb +1 -0
- data/lib/mongo/monitoring/publishable.rb +22 -12
- data/lib/mongo/monitoring.rb +1 -5
- data/lib/mongo/operation/commands/aggregate/result.rb +89 -0
- data/lib/mongo/operation/commands/aggregate.rb +64 -0
- data/lib/mongo/operation/commands/collections_info/result.rb +41 -0
- data/lib/mongo/operation/{read → commands}/collections_info.rb +5 -3
- data/lib/mongo/operation/commands/command.rb +47 -0
- data/lib/mongo/operation/commands/find/result.rb +62 -0
- data/lib/mongo/operation/commands/find.rb +27 -0
- data/lib/mongo/operation/commands/get_more/result.rb +62 -0
- data/lib/mongo/operation/commands/get_more.rb +27 -0
- data/lib/mongo/operation/{read → commands}/indexes.rb +9 -6
- data/lib/mongo/operation/{list_collections → commands/list_collections}/result.rb +1 -21
- data/lib/mongo/operation/{read → commands}/list_collections.rb +4 -32
- data/lib/mongo/operation/{list_indexes → commands/list_indexes}/result.rb +1 -21
- data/lib/mongo/operation/{read → commands}/list_indexes.rb +3 -33
- data/lib/mongo/operation/commands/map_reduce/result.rb +119 -0
- data/lib/mongo/operation/commands/map_reduce.rb +49 -0
- data/lib/mongo/operation/commands/parallel_scan/result.rb +64 -0
- data/lib/mongo/operation/commands/parallel_scan.rb +52 -0
- data/lib/mongo/operation/commands/user_query.rb +71 -0
- data/lib/mongo/operation/commands/users_info/result.rb +38 -0
- data/lib/mongo/operation/commands/users_info.rb +48 -0
- data/lib/mongo/operation/commands.rb +26 -0
- data/lib/mongo/operation/executable.rb +4 -68
- data/lib/mongo/operation/kill_cursors.rb +3 -3
- data/lib/mongo/operation/object_id_generator.rb +36 -0
- data/lib/mongo/operation/read/get_more.rb +2 -22
- data/lib/mongo/operation/read/query/result.rb +40 -0
- data/lib/mongo/operation/read/query.rb +4 -21
- data/lib/mongo/operation/read.rb +0 -4
- data/lib/mongo/operation/{read_preferrable.rb → read_preference.rb} +3 -2
- data/lib/mongo/operation/result.rb +43 -1
- data/lib/mongo/operation/specifiable.rb +59 -1
- data/lib/mongo/operation/write/bulk/bulkable.rb +83 -0
- data/lib/mongo/operation/write/bulk/delete/result.rb +67 -0
- data/lib/mongo/operation/write/bulk/delete.rb +71 -0
- data/lib/mongo/operation/write/bulk/insert/result.rb +129 -0
- data/lib/mongo/operation/write/bulk/insert.rb +96 -0
- data/lib/mongo/operation/write/bulk/legacy_mergable.rb +87 -0
- data/lib/mongo/operation/write/bulk/mergable.rb +71 -0
- data/lib/mongo/operation/write/bulk/update/result.rb +174 -0
- data/lib/mongo/operation/write/bulk/update.rb +81 -0
- data/lib/mongo/operation/write/bulk.rb +6 -3
- data/lib/mongo/operation/write/command/create_index.rb +0 -1
- data/lib/mongo/operation/write/command/create_user.rb +0 -1
- data/lib/mongo/operation/write/command/delete.rb +3 -3
- data/lib/mongo/operation/write/command/drop_index.rb +0 -1
- data/lib/mongo/operation/write/command/insert.rb +4 -3
- data/lib/mongo/operation/write/command/remove_user.rb +0 -1
- data/lib/mongo/operation/write/command/update.rb +6 -4
- data/lib/mongo/operation/write/command/update_user.rb +0 -1
- data/lib/mongo/operation/write/command/writable.rb +13 -18
- data/lib/mongo/operation/write/create_index.rb +4 -27
- data/lib/mongo/operation/write/create_user.rb +4 -30
- data/lib/mongo/operation/write/delete.rb +6 -29
- data/lib/mongo/operation/write/drop_index.rb +3 -3
- data/lib/mongo/operation/write/gle.rb +49 -0
- data/lib/mongo/operation/write/idable.rb +24 -2
- data/lib/mongo/operation/write/insert.rb +2 -24
- data/lib/mongo/operation/write/remove_user.rb +4 -27
- data/lib/mongo/operation/write/update.rb +13 -36
- data/lib/mongo/operation/write/update_user.rb +4 -30
- data/lib/mongo/operation/write/write_command_enabled.rb +53 -0
- data/lib/mongo/operation/write.rb +2 -0
- data/lib/mongo/operation.rb +33 -5
- data/lib/mongo/options/mapper.rb +26 -2
- data/lib/mongo/options/redacted.rb +156 -0
- data/lib/mongo/options.rb +1 -0
- data/lib/mongo/protocol/bit_vector.rb +11 -9
- data/lib/mongo/protocol/delete.rb +78 -3
- data/lib/mongo/protocol/get_more.rb +59 -2
- data/lib/mongo/protocol/insert.rb +73 -1
- data/lib/mongo/protocol/kill_cursors.rb +66 -4
- data/lib/mongo/protocol/message.rb +44 -20
- data/lib/mongo/protocol/query.rb +153 -65
- data/lib/mongo/protocol/reply.rb +92 -1
- data/lib/mongo/protocol/serializers.rb +49 -40
- data/lib/mongo/protocol/update.rb +93 -1
- data/lib/mongo/retryable.rb +101 -0
- data/lib/mongo/server/connectable.rb +28 -8
- data/lib/mongo/server/connection.rb +52 -10
- data/lib/mongo/server/connection_pool/queue.rb +15 -0
- data/lib/mongo/server/connection_pool.rb +12 -15
- data/lib/mongo/server/description/features.rb +4 -2
- data/lib/mongo/server/description.rb +39 -3
- data/lib/mongo/server/monitor/connection.rb +49 -28
- data/lib/mongo/server/monitor.rb +3 -14
- data/lib/mongo/server.rb +31 -4
- data/lib/mongo/server_selector/selectable.rb +58 -32
- data/lib/mongo/server_selector.rb +19 -10
- data/lib/mongo/socket/ssl.rb +4 -1
- data/lib/mongo/socket/tcp.rb +2 -2
- data/lib/mongo/socket/unix.rb +5 -8
- data/lib/mongo/socket.rb +11 -4
- data/lib/mongo/uri.rb +245 -139
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern.rb +21 -6
- data/lib/mongo.rb +4 -4
- data/mongo.gemspec +1 -2
- data/spec/mongo/address/unix_spec.rb +1 -1
- data/spec/mongo/address_spec.rb +25 -0
- data/spec/mongo/auth/ldap/conversation_spec.rb +43 -0
- data/spec/mongo/auth/user/view_spec.rb +26 -1
- data/spec/mongo/bulk_write/ordered_combiner_spec.rb +284 -0
- data/spec/mongo/bulk_write/unordered_combiner_spec.rb +239 -0
- data/spec/mongo/bulk_write_spec.rb +385 -161
- data/spec/mongo/client_spec.rb +193 -23
- data/spec/mongo/cluster/topology/replica_set_spec.rb +2 -0
- data/spec/mongo/collection/view/aggregation_spec.rb +65 -0
- data/spec/mongo/collection/view/builder/find_command_spec.rb +167 -0
- data/spec/mongo/collection/view/builder/flags_spec.rb +106 -0
- data/spec/mongo/collection/view/builder/modifiers_spec.rb +210 -0
- data/spec/mongo/collection/view/builder/op_query_spec.rb +154 -0
- data/spec/mongo/collection/view/explainable_spec.rb +1 -2
- data/spec/mongo/collection/view/immutable_spec.rb +54 -0
- data/spec/mongo/collection/view/map_reduce_spec.rb +104 -9
- data/spec/mongo/collection/view/readable_spec.rb +109 -112
- data/spec/mongo/collection/view_spec.rb +119 -487
- data/spec/mongo/collection_spec.rb +1002 -33
- data/spec/mongo/command_monitoring_spec.rb +64 -0
- data/spec/mongo/connection_string_spec.rb +115 -0
- data/spec/mongo/cursor/builder/get_more_command_spec.rb +160 -0
- data/spec/mongo/cursor/builder/op_get_more_spec.rb +52 -0
- data/spec/mongo/cursor_spec.rb +10 -60
- data/spec/mongo/database_spec.rb +81 -12
- data/spec/mongo/dbref_spec.rb +4 -4
- data/spec/mongo/grid/file/chunk_spec.rb +6 -6
- data/spec/mongo/grid/file/{metadata_spec.rb → info_spec.rb} +29 -17
- data/spec/mongo/grid/file_spec.rb +8 -8
- data/spec/mongo/grid/fs_bucket_spec.rb +1020 -0
- data/spec/mongo/grid/stream/read_spec.rb +275 -0
- data/spec/mongo/grid/stream/write_spec.rb +440 -0
- data/spec/mongo/grid/stream_spec.rb +48 -0
- data/spec/mongo/gridfs_spec.rb +50 -0
- data/spec/mongo/index/view_spec.rb +41 -0
- data/spec/mongo/logger_spec.rb +0 -40
- data/spec/mongo/monitoring/command_log_subscriber_spec.rb +76 -0
- data/spec/mongo/monitoring/event/command_started_spec.rb +26 -0
- data/spec/mongo/monitoring/event/command_succeeded_spec.rb +26 -0
- data/spec/mongo/monitoring/event/secure_spec.rb +57 -0
- data/spec/mongo/operation/{aggregate → commands/aggregate}/result_spec.rb +1 -1
- data/spec/mongo/operation/commands/aggregate_spec.rb +69 -0
- data/spec/mongo/operation/{read → commands}/collections_info_spec.rb +1 -1
- data/spec/mongo/operation/{command_spec.rb → commands/command_spec.rb} +1 -19
- data/spec/mongo/operation/{read → commands}/indexes_spec.rb +1 -1
- data/spec/mongo/operation/{map_reduce_spec.rb → commands/map_reduce_spec.rb} +1 -19
- data/spec/mongo/operation/kill_cursors_spec.rb +1 -17
- data/spec/mongo/operation/read/get_more_spec.rb +0 -16
- data/spec/mongo/operation/read/query_spec.rb +19 -16
- data/spec/mongo/operation/{read_preferrable_spec.rb → read_preference_spec.rb} +11 -11
- data/spec/mongo/operation/result_spec.rb +19 -0
- data/spec/mongo/operation/write/bulk/{bulk_delete_spec.rb → delete_spec.rb} +17 -28
- data/spec/mongo/operation/write/bulk/{bulk_insert_spec.rb → insert_spec.rb} +1 -12
- data/spec/mongo/operation/write/bulk/{bulk_update_spec.rb → update_spec.rb} +7 -18
- data/spec/mongo/operation/write/command/delete_spec.rb +18 -9
- data/spec/mongo/operation/write/command/insert_spec.rb +18 -9
- data/spec/mongo/operation/write/command/update_spec.rb +18 -9
- data/spec/mongo/operation/write/delete_spec.rb +3 -3
- data/spec/mongo/operation/write/insert_spec.rb +0 -11
- data/spec/mongo/operation/write/update_spec.rb +6 -6
- data/spec/mongo/options/redacted_spec.rb +350 -0
- data/spec/mongo/protocol/delete_spec.rb +4 -4
- data/spec/mongo/protocol/get_more_spec.rb +4 -4
- data/spec/mongo/protocol/insert_spec.rb +3 -3
- data/spec/mongo/protocol/kill_cursors_spec.rb +8 -6
- data/spec/mongo/protocol/query_spec.rb +21 -7
- data/spec/mongo/protocol/update_spec.rb +5 -5
- data/spec/mongo/retryable_spec.rb +221 -0
- data/spec/mongo/server/connection_pool/queue_spec.rb +16 -0
- data/spec/mongo/server/connection_pool_spec.rb +42 -6
- data/spec/mongo/server/connection_spec.rb +86 -1
- data/spec/mongo/server/description/features_spec.rb +25 -0
- data/spec/mongo/server/description_spec.rb +42 -0
- data/spec/mongo/server/monitor_spec.rb +44 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +25 -59
- data/spec/mongo/server_selection_rtt_spec.rb +37 -57
- data/spec/mongo/server_selection_spec.rb +5 -3
- data/spec/mongo/server_selector/nearest_spec.rb +35 -27
- data/spec/mongo/server_selector/primary_preferred_spec.rb +32 -30
- data/spec/mongo/server_selector/primary_spec.rb +21 -14
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +28 -26
- data/spec/mongo/server_selector/secondary_spec.rb +24 -22
- data/spec/mongo/server_selector_spec.rb +87 -24
- data/spec/mongo/server_spec.rb +78 -15
- data/spec/mongo/socket/ssl_spec.rb +101 -57
- data/spec/mongo/socket/unix_spec.rb +52 -0
- data/spec/mongo/uri_spec.rb +271 -59
- data/spec/mongo/write_concern_spec.rb +126 -0
- data/spec/spec_helper.rb +29 -23
- data/spec/support/authorization.rb +4 -5
- data/spec/support/command_monitoring/bulkWrite.yml +73 -0
- data/spec/support/command_monitoring/command.yml +42 -0
- data/spec/support/command_monitoring/deleteMany.yml +55 -0
- data/spec/support/command_monitoring/deleteOne.yml +55 -0
- data/spec/support/command_monitoring/find.yml +268 -0
- data/spec/support/command_monitoring/insertMany.yml +81 -0
- data/spec/support/command_monitoring/insertOne.yml +51 -0
- data/spec/support/command_monitoring/updateMany.yml +67 -0
- data/spec/support/command_monitoring/updateOne.yml +95 -0
- data/spec/support/command_monitoring.rb +373 -0
- data/spec/support/connection_string.rb +228 -0
- data/spec/support/connection_string_tests/invalid-uris.yml +193 -0
- data/spec/support/connection_string_tests/valid-auth.yml +256 -0
- data/spec/support/connection_string_tests/valid-host_identifiers.yml +121 -0
- data/spec/support/connection_string_tests/valid-options.yml +30 -0
- data/spec/support/connection_string_tests/valid-unix_socket-absolute.yml +197 -0
- data/spec/support/connection_string_tests/valid-unix_socket-relative.yml +213 -0
- data/spec/support/connection_string_tests/valid-warnings.yml +55 -0
- data/spec/support/crud/read.rb +14 -10
- data/spec/support/crud/write.rb +36 -9
- data/spec/support/crud.rb +10 -2
- data/spec/support/gridfs.rb +637 -0
- data/spec/support/gridfs_tests/delete.yml +157 -0
- data/spec/support/gridfs_tests/download.yml +210 -0
- data/spec/support/gridfs_tests/download_by_name.yml +113 -0
- data/spec/support/gridfs_tests/upload.yml +158 -0
- data/spec/support/matchers.rb +2 -2
- data/spec/support/sdam/rs/equal_electionids.yml +1 -2
- data/spec/support/sdam/rs/new_primary_new_electionid.yml +0 -3
- data/spec/support/sdam/rs/primary_mismatched_me.yml +37 -0
- data/spec/support/sdam/rs/primary_to_no_primary_mismatched_me.yml +75 -0
- data/spec/support/sdam/rs/rsother_discovered.yml +24 -3
- data/spec/support/sdam/rs/secondary_mismatched_me.yml +37 -0
- data/spec/support/sdam/rs/stepdown_change_set_name.yml +59 -0
- data/spec/support/sdam/single/direct_connection_rsarbiter.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rsprimary.yml +1 -1
- data/spec/support/sdam/single/direct_connection_rssecondary.yml +1 -1
- data/spec/support/sdam/single/direct_connection_slave.yml +1 -1
- data/spec/support/sdam/single/direct_connection_standalone.yml +1 -1
- data/spec/support/sdam/single/not_ok_response.yml +0 -1
- data/spec/support/server_discovery_and_monitoring.rb +3 -1
- data/spec/support/server_selection.rb +3 -1
- data/spec/support/shared/bulk_write.rb +192 -0
- data/spec/support/shared/protocol.rb +5 -5
- data/spec/support/shared/server_selector.rb +78 -13
- data/spec/support/travis.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +211 -72
- metadata.gz.sig +0 -0
- data/lib/mongo/bulk_write/bulk_writable.rb +0 -252
- data/lib/mongo/bulk_write/deletable.rb +0 -57
- data/lib/mongo/bulk_write/insertable.rb +0 -49
- data/lib/mongo/bulk_write/replacable.rb +0 -58
- data/lib/mongo/bulk_write/updatable.rb +0 -69
- data/lib/mongo/grid/fs.rb +0 -146
- data/lib/mongo/operation/aggregate/result.rb +0 -103
- data/lib/mongo/operation/aggregate.rb +0 -108
- data/lib/mongo/operation/command.rb +0 -61
- data/lib/mongo/operation/map_reduce/result.rb +0 -122
- data/lib/mongo/operation/map_reduce.rb +0 -95
- data/lib/mongo/operation/parallel_scan/result.rb +0 -72
- data/lib/mongo/operation/parallel_scan.rb +0 -76
- data/lib/mongo/operation/write/bulk/bulk_delete/result.rb +0 -75
- data/lib/mongo/operation/write/bulk/bulk_delete.rb +0 -145
- data/lib/mongo/operation/write/bulk/bulk_insert/result.rb +0 -130
- data/lib/mongo/operation/write/bulk/bulk_insert.rb +0 -132
- data/lib/mongo/operation/write/bulk/bulk_mergable.rb +0 -67
- data/lib/mongo/operation/write/bulk/bulk_update/result.rb +0 -174
- data/lib/mongo/operation/write/bulk/bulk_update.rb +0 -154
- data/lib/mongo/operation/write/bulk/legacy_bulk_mergable.rb +0 -83
- data/spec/mongo/grid/fs_spec.rb +0 -160
- data/spec/mongo/loggable_spec.rb +0 -63
- data/spec/mongo/operation/aggregate_spec.rb +0 -127
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
def skippable?(file)
|
4
|
+
!write_command_enabled? && (file.include?('bulkWrite') || file.include?('insert'))
|
5
|
+
end
|
6
|
+
|
7
|
+
def ignore?(test)
|
8
|
+
if version = test.ignore_if_server_version_greater_than
|
9
|
+
return true if version == "3.0" && find_command_enabled?
|
10
|
+
end
|
11
|
+
if version = test.ignore_if_server_version_less_than
|
12
|
+
return true if version == "3.1" && !find_command_enabled?
|
13
|
+
end
|
14
|
+
false
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'Command Monitoring Events' do
|
18
|
+
|
19
|
+
COMMAND_MONITORING_TESTS.each do |file|
|
20
|
+
|
21
|
+
if !skippable?(file)
|
22
|
+
|
23
|
+
spec = Mongo::CommandMonitoring::Spec.new(file)
|
24
|
+
|
25
|
+
spec.tests.each do |test|
|
26
|
+
|
27
|
+
context(test.description) do
|
28
|
+
|
29
|
+
let(:subscriber) do
|
30
|
+
Mongo::CommandMonitoring::TestSubscriber.new
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:monitoring) do
|
34
|
+
authorized_client.instance_variable_get(:@monitoring)
|
35
|
+
end
|
36
|
+
|
37
|
+
before do
|
38
|
+
authorized_collection.find.delete_many
|
39
|
+
authorized_client.subscribe(Mongo::Monitoring::COMMAND, subscriber)
|
40
|
+
end
|
41
|
+
|
42
|
+
after do
|
43
|
+
monitoring.subscribers[Mongo::Monitoring::COMMAND].delete(subscriber)
|
44
|
+
authorized_collection.find.delete_many
|
45
|
+
end
|
46
|
+
|
47
|
+
test.expectations.each do |expectation|
|
48
|
+
|
49
|
+
it "generates a #{expectation.event_name} for #{expectation.command_name}", unless: ignore?(test) do
|
50
|
+
begin
|
51
|
+
test.run(authorized_collection)
|
52
|
+
event = subscriber.send(expectation.event_type)[expectation.command_name]
|
53
|
+
expect(event).to send(expectation.matcher, expectation)
|
54
|
+
rescue Mongo::Error::OperationFailure, Mongo::Error::BulkWriteError => e
|
55
|
+
event = subscriber.send(expectation.event_type)[expectation.command_name]
|
56
|
+
expect(event).to send(expectation.matcher, expectation)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'ConnectionString' do
|
4
|
+
include Mongo::ConnectionString
|
5
|
+
|
6
|
+
CONNECTION_STRING_TESTS.each do |file|
|
7
|
+
|
8
|
+
spec = Mongo::ConnectionString::Spec.new(file)
|
9
|
+
|
10
|
+
context(spec.description) do
|
11
|
+
|
12
|
+
before(:all) do
|
13
|
+
|
14
|
+
module Mongo
|
15
|
+
class Address
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
alias :original_initialize_resolver! :initialize_resolver!
|
20
|
+
def initialize_resolver!(timeout, ssl_options)
|
21
|
+
family = (host == 'localhost') ? ::Socket::AF_INET : ::Socket::AF_UNSPEC
|
22
|
+
info = ::Socket.getaddrinfo(host, nil, family, ::Socket::SOCK_STREAM)
|
23
|
+
FAMILY_MAP[info.first[4]].new(info[3], port, host)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Server
|
28
|
+
|
29
|
+
# The constructor keeps the same API, but does not instantiate a
|
30
|
+
# monitor and run it.
|
31
|
+
alias :original_initialize :initialize
|
32
|
+
def initialize(address, cluster, monitoring, event_listeners, options = {})
|
33
|
+
@address = address
|
34
|
+
@cluster = cluster
|
35
|
+
@monitoring = monitoring
|
36
|
+
@options = options.freeze
|
37
|
+
@monitor = Monitor.new(address, event_listeners, options)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Disconnect simply needs to return true since we have no monitor and
|
41
|
+
# no connection.
|
42
|
+
alias :original_disconnect! :disconnect!
|
43
|
+
def disconnect!; true; end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
after(:all) do
|
49
|
+
|
50
|
+
module Mongo
|
51
|
+
# Return the implementations to their originals for the other
|
52
|
+
# tests in the suite.
|
53
|
+
class Address
|
54
|
+
alias :initialize_resolver! :original_initialize_resolver!
|
55
|
+
remove_method(:original_initialize_resolver!)
|
56
|
+
end
|
57
|
+
|
58
|
+
class Server
|
59
|
+
alias :initialize :original_initialize
|
60
|
+
remove_method(:original_initialize)
|
61
|
+
|
62
|
+
alias :disconnect! :original_disconnect!
|
63
|
+
remove_method(:original_disconnect!)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
spec.tests.each_with_index do |test, index|
|
69
|
+
|
70
|
+
context "when a #{test.description} is provided" do
|
71
|
+
|
72
|
+
|
73
|
+
context 'when the uri is invalid', unless: test.valid? do
|
74
|
+
|
75
|
+
it 'raises an error' do
|
76
|
+
expect{
|
77
|
+
test.uri
|
78
|
+
}.to raise_exception(Mongo::Error::InvalidURI)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when the uri should warn', if: test.warn? do
|
83
|
+
|
84
|
+
before do
|
85
|
+
expect(Mongo::Logger.logger).to receive(:warn)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'warns' do
|
89
|
+
expect(test.client).to be_a(Mongo::Client)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when the uri is valid', if: test.valid? do
|
94
|
+
|
95
|
+
it 'does not raise an exception' do
|
96
|
+
expect(test.uri).to be_a(Mongo::URI)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'creates a client with the correct hosts' do
|
100
|
+
expect(test.client).to have_hosts(test)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'creates a client with the correct authentication properties' do
|
104
|
+
expect(test.client).to match_auth(test)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'creates a client with the correct options' do
|
108
|
+
expect(test.client).to match_options(test)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongo::Cursor::Builder::GetMoreCommand do
|
4
|
+
|
5
|
+
describe '#specification' do
|
6
|
+
|
7
|
+
let(:reply) do
|
8
|
+
Mongo::Protocol::Reply.allocate
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:result) do
|
12
|
+
Mongo::Operation::Result.new(reply)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:cursor) do
|
16
|
+
Mongo::Cursor.new(view, result, authorized_primary)
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:builder) do
|
20
|
+
described_class.new(cursor)
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:specification) do
|
24
|
+
builder.specification
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:selector) do
|
28
|
+
specification[:selector]
|
29
|
+
end
|
30
|
+
|
31
|
+
shared_examples_for 'a getmore command builder' do
|
32
|
+
|
33
|
+
it 'includes the database name' do
|
34
|
+
expect(specification[:db_name]).to eq(TEST_DB)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'includes getmore with cursor id' do
|
38
|
+
expect(selector[:getMore]).to eq(cursor.id)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'includes the collection name' do
|
42
|
+
expect(selector[:collection]).to eq(TEST_COLL)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when the query is standard' do
|
47
|
+
|
48
|
+
let(:view) do
|
49
|
+
Mongo::Collection::View.new(authorized_collection)
|
50
|
+
end
|
51
|
+
|
52
|
+
it_behaves_like 'a getmore command builder'
|
53
|
+
|
54
|
+
it 'does not include max time' do
|
55
|
+
expect(selector[:maxTimeMS]).to be_nil
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'does not include batch size' do
|
59
|
+
expect(selector[:batchSize]).to be_nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when the query has a batch size' do
|
64
|
+
|
65
|
+
let(:view) do
|
66
|
+
Mongo::Collection::View.new(authorized_collection, {}, batch_size: 10)
|
67
|
+
end
|
68
|
+
|
69
|
+
it_behaves_like 'a getmore command builder'
|
70
|
+
|
71
|
+
it 'does not include max time' do
|
72
|
+
expect(selector[:maxTimeMS]).to be_nil
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'includes batch size' do
|
76
|
+
expect(selector[:batchSize]).to eq(10)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when a max await time is specified' do
|
81
|
+
|
82
|
+
context 'when the cursor is not tailable' do
|
83
|
+
|
84
|
+
let(:view) do
|
85
|
+
Mongo::Collection::View.new(authorized_collection, {}, max_await_time_ms: 100)
|
86
|
+
end
|
87
|
+
|
88
|
+
it_behaves_like 'a getmore command builder'
|
89
|
+
|
90
|
+
it 'does not include max time' do
|
91
|
+
expect(selector[:maxTimeMS]).to be_nil
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'does not include max await time' do
|
95
|
+
expect(selector[:maxAwaitTimeMS]).to be_nil
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'does not include batch size' do
|
99
|
+
expect(selector[:batchSize]).to be_nil
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'when the cursor is tailable' do
|
104
|
+
|
105
|
+
context 'when await data is true' do
|
106
|
+
|
107
|
+
let(:view) do
|
108
|
+
Mongo::Collection::View.new(
|
109
|
+
authorized_collection,
|
110
|
+
{},
|
111
|
+
await_data: true,
|
112
|
+
tailable: true,
|
113
|
+
max_await_time_ms: 100
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
it_behaves_like 'a getmore command builder'
|
118
|
+
|
119
|
+
it 'includes max time' do
|
120
|
+
expect(selector[:maxTimeMS]).to eq(100)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'does not include max await time' do
|
124
|
+
expect(selector[:maxAwaitTimeMS]).to be_nil
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'does not include batch size' do
|
128
|
+
expect(selector[:batchSize]).to be_nil
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'when await data is false' do
|
133
|
+
|
134
|
+
let(:view) do
|
135
|
+
Mongo::Collection::View.new(
|
136
|
+
authorized_collection,
|
137
|
+
{},
|
138
|
+
tailable: true,
|
139
|
+
max_await_time_ms: 100
|
140
|
+
)
|
141
|
+
end
|
142
|
+
|
143
|
+
it_behaves_like 'a getmore command builder'
|
144
|
+
|
145
|
+
it 'does not include max time' do
|
146
|
+
expect(selector[:maxTimeMS]).to be_nil
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'does not include max await time' do
|
150
|
+
expect(selector[:maxAwaitTimeMS]).to be_nil
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'does not include batch size' do
|
154
|
+
expect(selector[:batchSize]).to be_nil
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongo::Cursor::Builder::OpGetMore do
|
4
|
+
|
5
|
+
describe '#specification' do
|
6
|
+
|
7
|
+
let(:reply) do
|
8
|
+
Mongo::Protocol::Reply.allocate
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:result) do
|
12
|
+
Mongo::Operation::Result.new(reply)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:view) do
|
16
|
+
Mongo::Collection::View.new(
|
17
|
+
authorized_collection,
|
18
|
+
{},
|
19
|
+
tailable: true,
|
20
|
+
max_time_ms: 100
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:cursor) do
|
25
|
+
Mongo::Cursor.new(view, result, authorized_primary)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:builder) do
|
29
|
+
described_class.new(cursor)
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:specification) do
|
33
|
+
builder.specification
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'includes to return' do
|
37
|
+
expect(specification[:to_return]).to eq(0)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'includes the cursor id' do
|
41
|
+
expect(specification[:cursor_id]).to eq(cursor.id)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'includes the database name' do
|
45
|
+
expect(specification[:db_name]).to eq(TEST_DB)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'includes the collection name' do
|
49
|
+
expect(specification[:coll_name]).to eq(TEST_COLL)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/spec/mongo/cursor_spec.rb
CHANGED
@@ -4,12 +4,16 @@ describe Mongo::Cursor do
|
|
4
4
|
|
5
5
|
describe '#each' do
|
6
6
|
|
7
|
+
let(:server) do
|
8
|
+
view.read.select_server(authorized_client.cluster)
|
9
|
+
end
|
10
|
+
|
7
11
|
let(:reply) do
|
8
|
-
|
12
|
+
view.send(:send_initial_query, server)
|
9
13
|
end
|
10
14
|
|
11
15
|
let(:cursor) do
|
12
|
-
described_class.new(view, reply,
|
16
|
+
described_class.new(view, reply, server)
|
13
17
|
end
|
14
18
|
|
15
19
|
context 'when no options are provided to the view' do
|
@@ -18,10 +22,6 @@ describe Mongo::Cursor do
|
|
18
22
|
Mongo::Collection::View.new(authorized_collection)
|
19
23
|
end
|
20
24
|
|
21
|
-
let(:query_spec) do
|
22
|
-
{ :selector => {}, :options => {}, :db_name => TEST_DB, :coll_name => TEST_COLL }
|
23
|
-
end
|
24
|
-
|
25
25
|
context 'when the initial query retieves all documents' do
|
26
26
|
|
27
27
|
let(:documents) do
|
@@ -97,15 +97,6 @@ describe Mongo::Cursor do
|
|
97
97
|
Mongo::Collection::View.new(authorized_collection, {}, :limit => 2)
|
98
98
|
end
|
99
99
|
|
100
|
-
let(:query_spec) do
|
101
|
-
{
|
102
|
-
:selector => {},
|
103
|
-
:options => { :limit => 2 },
|
104
|
-
:db_name => TEST_DB,
|
105
|
-
:coll_name => TEST_COLL
|
106
|
-
}
|
107
|
-
end
|
108
|
-
|
109
100
|
it 'returns the correct amount' do
|
110
101
|
expect(cursor.to_a.count).to eq(2)
|
111
102
|
end
|
@@ -123,17 +114,12 @@ describe Mongo::Cursor do
|
|
123
114
|
Mongo::Collection::View.new(authorized_collection, {}, :limit => -2)
|
124
115
|
end
|
125
116
|
|
126
|
-
|
127
|
-
|
128
|
-
:selector => {},
|
129
|
-
:options => { :limit => -2 },
|
130
|
-
:db_name => TEST_DB,
|
131
|
-
:coll_name => TEST_COLL
|
132
|
-
}
|
117
|
+
it 'returns the positive number of documents', unless: find_command_enabled? do
|
118
|
+
expect(cursor.to_a.count).to eq(2)
|
133
119
|
end
|
134
120
|
|
135
|
-
it 'returns
|
136
|
-
expect(cursor.to_a.count).to eq(
|
121
|
+
it 'returns all documents', if: find_command_enabled? do
|
122
|
+
expect(cursor.to_a.count).to eq(10)
|
137
123
|
end
|
138
124
|
|
139
125
|
it 'iterates the documents' do
|
@@ -149,15 +135,6 @@ describe Mongo::Cursor do
|
|
149
135
|
Mongo::Collection::View.new(authorized_collection, {}, :limit => 0)
|
150
136
|
end
|
151
137
|
|
152
|
-
let(:query_spec) do
|
153
|
-
{
|
154
|
-
:selector => {},
|
155
|
-
:options => { :limit => 0 },
|
156
|
-
:db_name => TEST_DB,
|
157
|
-
:coll_name => TEST_COLL
|
158
|
-
}
|
159
|
-
end
|
160
|
-
|
161
138
|
it 'returns all documents' do
|
162
139
|
expect(cursor.to_a.count).to eq(10)
|
163
140
|
end
|
@@ -182,15 +159,6 @@ describe Mongo::Cursor do
|
|
182
159
|
)
|
183
160
|
end
|
184
161
|
|
185
|
-
let(:query_spec) do
|
186
|
-
{
|
187
|
-
:selector => {},
|
188
|
-
:options => { :limit => 5, :batch_size => 3 },
|
189
|
-
:db_name => TEST_DB,
|
190
|
-
:coll_name => TEST_COLL
|
191
|
-
}
|
192
|
-
end
|
193
|
-
|
194
162
|
it 'returns the limited number of documents' do
|
195
163
|
expect(cursor.to_a.count).to eq(5)
|
196
164
|
end
|
@@ -212,15 +180,6 @@ describe Mongo::Cursor do
|
|
212
180
|
)
|
213
181
|
end
|
214
182
|
|
215
|
-
let(:query_spec) do
|
216
|
-
{
|
217
|
-
:selector => {},
|
218
|
-
:options => { :limit => 5, :batch_size => 7 },
|
219
|
-
:db_name => TEST_DB,
|
220
|
-
:coll_name => TEST_COLL
|
221
|
-
}
|
222
|
-
end
|
223
|
-
|
224
183
|
it 'returns the limited number of documents' do
|
225
184
|
expect(cursor.to_a.count).to eq(5)
|
226
185
|
end
|
@@ -242,15 +201,6 @@ describe Mongo::Cursor do
|
|
242
201
|
)
|
243
202
|
end
|
244
203
|
|
245
|
-
let(:query_spec) do
|
246
|
-
{
|
247
|
-
:selector => {},
|
248
|
-
:options => { :limit => 5, :batch_size => 5 },
|
249
|
-
:db_name => TEST_DB,
|
250
|
-
:coll_name => TEST_COLL
|
251
|
-
}
|
252
|
-
end
|
253
|
-
|
254
204
|
it 'returns the limited number of documents' do
|
255
205
|
expect(cursor.to_a.count).to eq(5)
|
256
206
|
end
|
data/spec/mongo/database_spec.rb
CHANGED
@@ -93,6 +93,26 @@ describe Mongo::Database do
|
|
93
93
|
expect(database.collection_names(batch_size: 1).to_a).to include('users')
|
94
94
|
end
|
95
95
|
end
|
96
|
+
|
97
|
+
context 'when there are more collections than the initial batch size' do
|
98
|
+
|
99
|
+
before do
|
100
|
+
2.times do |i|
|
101
|
+
database["#{i}_dalmatians"].create
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
after do
|
106
|
+
2.times do |i|
|
107
|
+
database["#{i}_dalmatians"].drop
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'returns all collections' do
|
112
|
+
expect(database.collection_names(batch_size: 1).select { |c| c =~ /dalmatians/}.size).to eq(2)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
96
116
|
end
|
97
117
|
|
98
118
|
describe '#list_collections' do
|
@@ -160,7 +180,7 @@ describe Mongo::Database do
|
|
160
180
|
end
|
161
181
|
end
|
162
182
|
|
163
|
-
context 'when the user is not authorized',
|
183
|
+
context 'when the user is not authorized', if: auth_enabled? do
|
164
184
|
|
165
185
|
let(:database) do
|
166
186
|
described_class.new(unauthorized_client, TEST_DB)
|
@@ -184,6 +204,27 @@ describe Mongo::Database do
|
|
184
204
|
expect(database.command(:ismaster => 1).written_count).to eq(0)
|
185
205
|
end
|
186
206
|
|
207
|
+
context 'when a read concern is provided', if: find_command_enabled? do
|
208
|
+
|
209
|
+
context 'when the read concern is valid' do
|
210
|
+
|
211
|
+
it 'sends the read concern' do
|
212
|
+
expect {
|
213
|
+
database.command(:ismaster => 1, readConcern: { level: 'local' })
|
214
|
+
}.to_not raise_error
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
context 'when the read concern is not valid' do
|
219
|
+
|
220
|
+
it 'raises an exception', if: (find_command_enabled? && !sharded?) do
|
221
|
+
expect {
|
222
|
+
database.command(:ismaster => 1, readConcern: { level: 'yay' })
|
223
|
+
}.to raise_error(Mongo::Error::OperationFailure)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
187
228
|
context 'when an alternate read preference is specified' do
|
188
229
|
|
189
230
|
before do
|
@@ -195,7 +236,7 @@ describe Mongo::Database do
|
|
195
236
|
end
|
196
237
|
|
197
238
|
let(:client) do
|
198
|
-
authorized_client.with(server_selection_timeout:
|
239
|
+
authorized_client.with(server_selection_timeout: 0.1)
|
199
240
|
end
|
200
241
|
|
201
242
|
let(:database) do
|
@@ -208,6 +249,18 @@ describe Mongo::Database do
|
|
208
249
|
end.to raise_error(Mongo::Error::NoServerAvailable)
|
209
250
|
end
|
210
251
|
end
|
252
|
+
|
253
|
+
context 'when there is a read preference set on the client' do
|
254
|
+
|
255
|
+
let(:database) do
|
256
|
+
described_class.new(authorized_client.with(read: { mode: :secondary }), TEST_DB)
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'does not use the read preference' do
|
260
|
+
expect(database.client.cluster).to receive(:next_primary).and_call_original
|
261
|
+
database.command(ping: 1)
|
262
|
+
end
|
263
|
+
end
|
211
264
|
end
|
212
265
|
|
213
266
|
describe '#drop' do
|
@@ -278,7 +331,7 @@ describe Mongo::Database do
|
|
278
331
|
shared_context 'a GridFS database' do
|
279
332
|
|
280
333
|
it 'returns a Grid::FS for the db' do
|
281
|
-
expect(fs).to be_a(Mongo::Grid::
|
334
|
+
expect(fs).to be_a(Mongo::Grid::FSBucket)
|
282
335
|
end
|
283
336
|
|
284
337
|
context 'when operating on the fs' do
|
@@ -292,8 +345,8 @@ describe Mongo::Database do
|
|
292
345
|
end
|
293
346
|
|
294
347
|
after do
|
295
|
-
fs.files_collection.
|
296
|
-
fs.chunks_collection.
|
348
|
+
fs.files_collection.delete_many
|
349
|
+
fs.chunks_collection.delete_many
|
297
350
|
end
|
298
351
|
|
299
352
|
let(:from_db) do
|
@@ -301,7 +354,7 @@ describe Mongo::Database do
|
|
301
354
|
end
|
302
355
|
|
303
356
|
it 'returns the assembled file from the db' do
|
304
|
-
expect(from_db.filename).to eq(file.
|
357
|
+
expect(from_db.filename).to eq(file.info.filename)
|
305
358
|
end
|
306
359
|
end
|
307
360
|
end
|
@@ -317,15 +370,31 @@ describe Mongo::Database do
|
|
317
370
|
|
318
371
|
context 'when a custom prefix is provided' do
|
319
372
|
|
320
|
-
|
321
|
-
database.fs(:fs_name => 'grid')
|
322
|
-
end
|
373
|
+
context 'when the option is fs_name' do
|
323
374
|
|
324
|
-
|
325
|
-
|
375
|
+
let(:fs) do
|
376
|
+
database.fs(:fs_name => 'grid')
|
377
|
+
end
|
378
|
+
|
379
|
+
it 'sets the custom prefix' do
|
380
|
+
expect(fs.prefix).to eq('grid')
|
381
|
+
end
|
382
|
+
|
383
|
+
it_behaves_like 'a GridFS database'
|
326
384
|
end
|
327
385
|
|
328
|
-
|
386
|
+
context 'when the option is bucket_name' do
|
387
|
+
|
388
|
+
let(:fs) do
|
389
|
+
database.fs(:bucket_name => 'grid')
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'sets the custom prefix' do
|
393
|
+
expect(fs.prefix).to eq('grid')
|
394
|
+
end
|
395
|
+
|
396
|
+
it_behaves_like 'a GridFS database'
|
397
|
+
end
|
329
398
|
end
|
330
399
|
end
|
331
400
|
end
|
data/spec/mongo/dbref_spec.rb
CHANGED
@@ -69,7 +69,7 @@ describe Mongo::DBRef do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'converts the underlying document to bson' do
|
72
|
-
expect(dbref.to_bson).to eq(dbref.as_json.to_bson)
|
72
|
+
expect(dbref.to_bson.to_s).to eq(dbref.as_json.to_bson.to_s)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -100,12 +100,12 @@ describe Mongo::DBRef do
|
|
100
100
|
|
101
101
|
describe '#from_bson' do
|
102
102
|
|
103
|
-
let(:
|
104
|
-
|
103
|
+
let(:buffer) do
|
104
|
+
dbref.to_bson
|
105
105
|
end
|
106
106
|
|
107
107
|
let(:decoded) do
|
108
|
-
BSON::Document.from_bson(
|
108
|
+
BSON::Document.from_bson(BSON::ByteBuffer.new(buffer.to_s))
|
109
109
|
end
|
110
110
|
|
111
111
|
context 'when a database exists' do
|