Skip to content

Commit 00ac5be

Browse files
committed
fix failing specs
1 parent 3ab9296 commit 00ac5be

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

lib/mongo/client.rb

+25-21
Original file line numberDiff line numberDiff line change
@@ -1362,27 +1362,27 @@ def cluster_modifying?(new_options)
13621362
# The argument may contain a subset of options that the client will
13631363
# eventually have; this method validates each of the provided options
13641364
# but does not check for interactions between combinations of options.
1365-
def validate_new_options!(opts)
1366-
return Options::Redacted.new unless opts
1367-
1368-
validate_read_concern!(opts[:read_concern])
1369-
validate_server_api!(opts[:server_api])
1370-
validate_max_min_pool_size!(opts)
1371-
validate_max_connecting!(opts)
1372-
validate_read!(opts)
1373-
validate_compressors!(opts)
1374-
validate_srv_max_hosts!(opts)
1375-
1376-
invalid_options = opts.keys.map(&:to_sym) - VALID_OPTIONS
1377-
if invalid_options.any?
1378-
log_warn("Unsupported client options: #{invalid_options.join(', ')}. These will be ignored.")
1379-
opts = opts.select { |key,| VALID_OPTIONS.include?(key.to_sym) }
1380-
end
1381-
1382-
Lint.validate_underscore_read_preference(opts[:read])
1383-
Lint.validate_read_concern_option(opts[:read_concern])
1365+
def validate_new_options!(options)
1366+
return Options::Redacted.new unless options
1367+
1368+
Options::Redacted.new(options).tap do |opts|
1369+
validate_read_concern!(opts[:read_concern])
1370+
validate_server_api!(opts[:server_api])
1371+
validate_max_min_pool_size!(opts)
1372+
validate_max_connecting!(opts)
1373+
validate_read!(opts)
1374+
validate_compressors!(opts)
1375+
validate_srv_max_hosts!(opts)
1376+
1377+
invalid_options = opts.keys.map(&:to_sym) - VALID_OPTIONS
1378+
if invalid_options.any?
1379+
log_warn("Unsupported client options: #{invalid_options.join(', ')}. These will be ignored.")
1380+
opts.delete_if { |key,| !VALID_OPTIONS.include?(key.to_sym) }
1381+
end
13841382

1385-
Options::Redacted.new(opts)
1383+
Lint.validate_underscore_read_preference(opts[:read])
1384+
Lint.validate_read_concern_option(opts[:read_concern])
1385+
end
13861386
end
13871387

13881388
# Validates all options after they are set on the client.
@@ -1645,7 +1645,11 @@ def validate_compressors!(opts)
16451645
validate_zstd_compression!
16461646
end
16471647

1648-
opts[:compressors] = compressors unless compressors.empty?
1648+
if compressors.empty?
1649+
opts.delete(:compressors)
1650+
else
1651+
opts[:compressors] = compressors
1652+
end
16491653
end
16501654

16511655
def validate_snappy_compression!

spec/mongo/client_construction_spec.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,9 @@
817817
{ max_connecting: -5 }
818818
end
819819

820-
it 'raises an exception' do
821-
expect { client }.to raise_error(Mongo::Error::InvalidMaxConnecting)
820+
it 'logs a warning' do
821+
expect(Mongo::Logger.logger).to receive(:warn).with(/Invalid max_connecting/)
822+
client
822823
end
823824
end
824825
end
@@ -1035,13 +1036,14 @@
10351036
end
10361037
end
10371038

1038-
context 'when max_connecting is a negative integer' do
1039+
context 'when max_connecting is zero' do
10391040
let(:uri) do
10401041
'mongodb://127.0.0.1:27017/?maxConnecting=0'
10411042
end
10421043

1043-
it 'raises an exception' do
1044-
expect { client }.to raise_error(Mongo::Error::InvalidMaxConnecting)
1044+
it 'logs a warning' do
1045+
expect(Mongo::Logger.logger).to receive(:warn).with(/Invalid max_connecting/)
1046+
client
10451047
end
10461048
end
10471049
end

0 commit comments

Comments
 (0)