DEV: test custom param encoder behavior

DEV: test custom param encoder behavior

This codifies how we expect param encoder to work across connections

Also adds a pattern for custom connection init is connection tests

diff --git a/test/mini_sql/connection_tests.rb b/test/mini_sql/connection_tests.rb
index 873a476..5a82254 100644
--- a/test/mini_sql/connection_tests.rb
+++ b/test/mini_sql/connection_tests.rb
@@ -1,6 +1,24 @@
 # frozen_string_literal: true
 
 module MiniSql::ConnectionTests
+  class BadEncoder
+    # doest not implement encode
+  end
+
+  class OddEncoder
+    def encode(sql, *params)
+      sql + params.join(",")
+    end
+  end
+
+  def test_custom_param_encoder_not_called
+    new_connection(param_encoder: BadEncoder.new).exec("select 1")
+  end
+
+  def test_custom_param_encoder_called
+    array = new_connection(param_encoder: OddEncoder.new).query_single("select ", 1, 2)
+    assert_equal(array, [1, 2])
+  end
 
   def test_can_exec_sql
     @connection.exec("create temp table testing ( a int )")
@@ -130,7 +148,7 @@ module MiniSql::ConnectionTests
 
     r = @connection.query('select 20 price, 3 quantity').first
     refute(r.respond_to? :amount_price)
-    assert_equal(nil, r.class.decorator)
+    assert_nil(r.class.decorator)
   end
 
   def test_serializers
diff --git a/test/mini_sql/mysql/connection_test.rb b/test/mini_sql/mysql/connection_test.rb
index 3614f36..c66e553 100644
--- a/test/mini_sql/mysql/connection_test.rb
+++ b/test/mini_sql/mysql/connection_test.rb
@@ -8,6 +8,10 @@ class MiniSql::Mysql::TestConnection < MiniTest::Test
     @connection = mysql_connection
   end
 
+  def new_connection(opts = {})
+    mysql_connection(opts)
+  end
+
   include MiniSql::ConnectionTests
 
   def test_can_exec_sql
diff --git a/test/mini_sql/postgres/connection_test.rb b/test/mini_sql/postgres/connection_test.rb
index 974f1aa..7d82bc8 100644
--- a/test/mini_sql/postgres/connection_test.rb
+++ b/test/mini_sql/postgres/connection_test.rb
@@ -7,12 +7,15 @@ class MiniSql::Postgres::TestConnection < MiniTest::Test
     @connection = pg_connection
   end
 
+  def new_connection(opts = {})
+    pg_connection(opts)
+  end
+
   include MiniSql::ConnectionTests
 
   def test_custom_type_map
-    pg_conn = PG.connect(dbname: 'test_mini_sql')
     map = PG::TypeMapByOid.new
-    cnn = MiniSql::Connection.get(pg_conn, type_map: map)
+    cnn = pg_connection(type_map: map)
     assert_equal(map, cnn.type_map)
     # OID type map is limited and just does text
     assert_equal("1", cnn.query("select 1 a").first.a)
diff --git a/test/mini_sql/sqlite/connection_test.rb b/test/mini_sql/sqlite/connection_test.rb
index 7abe6cd..b6ed5f9 100644
--- a/test/mini_sql/sqlite/connection_test.rb
+++ b/test/mini_sql/sqlite/connection_test.rb
@@ -8,5 +8,9 @@ class MiniSql::Sqlite::TestConnection < MiniTest::Test
     @connection = sqlite3_connection
   end
 
+  def new_connection(opts = {})
+    mysql_connection(opts)
+  end
+
   include MiniSql::ConnectionTests
 end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index e5e9e43..c5aa0f2 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -22,8 +22,8 @@ else
   require "sqlite3"
   require "mysql2"
 
-  def mysql_connection
-    args = { database: 'test_mini_sql', username: 'root' }
+  def mysql_connection(options = {})
+    args = { database: 'test_mini_sql', username: 'root', password: '' }
     %i[port host password].each do |name|
       if val = ENV["MINI_SQL_MYSQL_#{name.upcase}"]
         args[name] = val
@@ -32,17 +32,17 @@ else
     mysql_conn = Mysql2::Client.new(**args)
     mysql_conn.query("create TEMPORARY table IF NOT EXISTS for_testing ( a int )")
     mysql_conn.query("insert into for_testing values (1)")
-    MiniSql::Connection.get(mysql_conn)
+    MiniSql::Connection.get(mysql_conn, options)
   end
 
-  def pg_connection
+  def pg_connection(options = {})
     pg_conn = PG.connect(dbname: 'test_mini_sql')
-    MiniSql::Connection.get(pg_conn)
+    MiniSql::Connection.get(pg_conn, options)
   end
 
-  def sqlite3_connection
+  def sqlite3_connection(options = {})
     sqlite_conn = SQLite3::Database.new(':memory:')
-    MiniSql::Connection.get(sqlite_conn)
+    MiniSql::Connection.get(sqlite_conn, options)
   end
 end
 

GitHub sha: 2d8bc05d