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 ce5b1cb
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 @@ -30,12 +30,6 @@ def test_trilogy_connect_with_native_password_auth_switch
ensure_closed client
end

def test_trilogy_connect_tcp_fixnum_port
assert_raises TypeError do
new_tcp_client port: "13306"
end
end

def test_trilogy_connect_tcp_to_wrong_port
e = assert_raises Trilogy::ConnectionError do
new_tcp_client port: 13307
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 ce5b1cb

Please sign in to comment.