Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/cassandra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ def self.cluster_async(options = {})
# @private
SSL_CLASSES = [::TrueClass, ::FalseClass, ::OpenSSL::SSL::SSLContext].freeze

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
# @private
def self.validate_and_massage_options(options)
options = options.select do |key, _|
Expand Down Expand Up @@ -633,6 +636,16 @@ def self.validate_and_massage_options(options)
end
end

if options.key?(:protocol_version)
protocol_version = options[:protocol_version]
unless protocol_version.nil?
Util.assert_instance_of(::Integer, protocol_version)
Util.assert_one_of(1..4, protocol_version) do
":protocol_version must be a positive integer, #{protocol_version.inspect} given"
end
end
end

if options.key?(:futures_factory)
futures_factory = options[:futures_factory]
methods = [:error, :value, :promise, :all]
Expand Down
10 changes: 10 additions & 0 deletions spec/cassandra_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ def unavailable
expect(C.validate(page_size: nil)).to eq({ page_size: nil })
end

it 'should validate :protocol_version' do
expect { C.validate(protocol_version: 'a') }.to raise_error(ArgumentError)
expect { C.validate(protocol_version: 0) }.to raise_error(ArgumentError)
expect { C.validate(protocol_version: 1.5) }.to raise_error(ArgumentError)
expect { C.validate(protocol_version: 5) }.to raise_error(ArgumentError)
expect(C.validate(protocol_version: 1)).to eq({ protocol_version: 1 })
expect(C.validate(protocol_version: 4)).to eq({ protocol_version: 4 })
expect(C.validate(protocol_version: nil)).to eq({ protocol_version: nil })
end

it 'should validate :futures_factory option' do
class GoodFactory
def error
Expand Down