Skip to content

Commit e0e8b41

Browse files
committed
Fix postgres version tests failures
we needed to add new_client class method similar to active record CRuby adapters so we can easily mock the raw_connection.
1 parent aac97a2 commit e0e8b41

File tree

5 files changed

+37
-28
lines changed

5 files changed

+37
-28
lines changed

lib/arjdbc/abstract/connection_management.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def disconnect!
4040

4141
# DIFFERENCE: we delve into jdbc shared code and this does self.class.new_client.
4242
def connect
43-
@raw_connection = jdbc_connection_class.new(@connection_parameters, self)
43+
@raw_connection = self.class.new_client(@connection_parameters, self)
4444
rescue ConnectionNotEstablished => ex
4545
raise ex.set_pool(@pool)
4646
end

lib/arjdbc/mysql/adapter.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ class Mysql2Adapter < AbstractMysqlAdapter
3333

3434
include ArJdbc::MySQL
3535

36+
class << self
37+
def jdbc_connection_class
38+
::ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
39+
end
40+
41+
def new_client(conn_params, adapter_instance)
42+
jdbc_connection_class.new(conn_params, adapter_instance)
43+
end
44+
end
45+
3646
def initialize(...)
3747
super
3848

@@ -221,10 +231,6 @@ def get_full_version
221231
@full_version ||= any_raw_connection.full_version
222232
end
223233

224-
def jdbc_connection_class
225-
::ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
226-
end
227-
228234
def jdbc_column_class
229235
::ActiveRecord::ConnectionAdapters::MySQL::Column
230236
end

lib/arjdbc/postgresql/adapter.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ module PostgreSQL
3535
# @private
3636
Type = ::ActiveRecord::Type
3737

38-
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
39-
def self.jdbc_connection_class
40-
::ActiveRecord::ConnectionAdapters::PostgreSQLJdbcConnection
41-
end
42-
4338
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class
4439
def jdbc_column_class; ::ActiveRecord::ConnectionAdapters::PostgreSQLColumn end
4540

@@ -763,6 +758,16 @@ class PostgreSQLAdapter < AbstractAdapter
763758
# AR expects OID to be available on the adapter
764759
OID = ActiveRecord::ConnectionAdapters::PostgreSQL::OID
765760

761+
class << self
762+
def jdbc_connection_class
763+
::ActiveRecord::ConnectionAdapters::PostgreSQLJdbcConnection
764+
end
765+
766+
def new_client(conn_params, adapter_instance)
767+
jdbc_connection_class.new(conn_params, adapter_instance)
768+
end
769+
end
770+
766771
def initialize(...)
767772
super
768773

@@ -796,10 +801,6 @@ def self.database_exists?(config)
796801
public :sql_for_insert
797802
alias :postgresql_version :database_version
798803

799-
def jdbc_connection_class
800-
::ArJdbc::PostgreSQL.jdbc_connection_class
801-
end
802-
803804
private
804805

805806
FEATURE_NOT_SUPPORTED = "0A000" # :nodoc:

lib/arjdbc/sqlite3/adapter.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -825,15 +825,6 @@ def jdbc_column_class
825825
::ActiveRecord::ConnectionAdapters::SQLite3Column
826826
end
827827

828-
def jdbc_connection_class
829-
self.class.jdbc_connection_class
830-
end
831-
832-
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
833-
def self.jdbc_connection_class
834-
::ActiveRecord::ConnectionAdapters::SQLite3JdbcConnection
835-
end
836-
837828
# Note: This is not an override of ours but a moved line from AR Sqlite3Adapter to register ours vs our copied module (which would be their class).
838829
# ActiveSupport.run_load_hooks(:active_record_sqlite3adapter, SQLite3Adapter)
839830

@@ -851,6 +842,14 @@ def _limit
851842
::ActiveRecord::Type.register(:integer, SQLite3Integer, adapter: :sqlite3)
852843

853844
class << self
845+
def jdbc_connection_class
846+
::ActiveRecord::ConnectionAdapters::SQLite3JdbcConnection
847+
end
848+
849+
def new_client(conn_params, adapter_instance)
850+
jdbc_connection_class.new(conn_params, adapter_instance)
851+
end
852+
854853
def dbconsole(config, options = {})
855854
args = []
856855

test/db/postgresql/version_test.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,15 @@ def test_pg_single_version
5050
private
5151

5252
def connection_stub(version, full_version = false)
53-
connection = mock('connection')
54-
connection.stubs(:jndi?)
55-
connection.stubs(:configure_connection)
56-
connection.expects(:database_product).returns full_version ? version.to_s : "PostgreSQL #{version}"
53+
raw_connection = mock('raw_connection')
54+
raw_connection.stubs(:execute)
55+
raw_connection.stubs(:exec_params)
56+
57+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.stubs(:new_client).returns(raw_connection)
5758
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.any_instance.stubs(:initialize_type_map)
58-
pg_connection = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.new(connection, nil, {})
59+
60+
raw_connection.expects(:database_product).returns(full_version ? version.to_s : "PostgreSQL #{version}").at_least_once
61+
pg_connection = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.new({})
5962
pg_connection.database_version
6063
end
6164
end

0 commit comments

Comments
 (0)