From e7fc57f1ce6796d124ca31c3de79d39201ff5122 Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Tue, 11 Jul 2023 14:08:54 -0500 Subject: [PATCH] Cast port to integer in connection options Support string ports to make ENV config passing easier. Other gems like mysql2 support this use-case, so I think trilogy should too. --- contrib/ruby/lib/trilogy.rb | 1 + contrib/ruby/test/client_test.rb | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/contrib/ruby/lib/trilogy.rb b/contrib/ruby/lib/trilogy.rb index 418e8b04..45e2d025 100644 --- a/contrib/ruby/lib/trilogy.rb +++ b/contrib/ruby/lib/trilogy.rb @@ -8,6 +8,7 @@ class Trilogy def initialize(options = {}) + options[:port] = options[:port].to_i if options.key?(:port) mysql_encoding = options[:encoding] || "utf8mb4" encoding = Trilogy::Encoding.find(mysql_encoding) charset = Trilogy::Encoding.charset(mysql_encoding) diff --git a/contrib/ruby/test/client_test.rb b/contrib/ruby/test/client_test.rb index 5c188cc6..a012d5ef 100644 --- a/contrib/ruby/test/client_test.rb +++ b/contrib/ruby/test/client_test.rb @@ -17,12 +17,6 @@ def test_trilogy_connect_tcp ensure_closed client end - def test_trilogy_connect_tcp_string_host - assert_raises TypeError do - new_tcp_client host: :localhost - end - end - def test_trilogy_connect_with_native_password_auth_switch client = new_tcp_client username: "native" refute_nil client @@ -1057,4 +1051,17 @@ def test_character_encoding_handles_binary_queries assert_equal expected.dup.force_encoding(Encoding::Windows_31J), result assert_equal Encoding::Windows_31J, result.encoding end + + def test_connection_options_casting + options = { + host: DEFAULT_HOST, + port: DEFAULT_PORT.to_s, + username: DEFAULT_USER, + password: DEFAULT_PASS, + ssl: "1", + } + client = new_tcp_client(**options) + + assert client.query("SELECT 1") + end end