Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast port to intrger in connection options #100

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
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