Skip to content

Commit

Permalink
Cast port to integer in connection options
Browse files Browse the repository at this point in the history
Support string ports to make ENV config passing easier. Other gems like
mysql2 support this use-case, so I think trilogy should too.
  • Loading branch information
gmcgibbon committed Jul 12, 2023
1 parent 640f990 commit e7fc57f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions contrib/ruby/lib/trilogy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 13 additions & 6 deletions contrib/ruby/test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit e7fc57f

Please sign in to comment.