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 11, 2023
1 parent 640f990 commit 3243f36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 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
13 changes: 13 additions & 0 deletions contrib/ruby/test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1057,4 +1057,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 3243f36

Please sign in to comment.