Skip to content

Commit 24e84f9

Browse files
committed
move PG_VERSION since it's only used in one test case + tune jdbc config
1 parent 9508af3 commit 24e84f9

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

test/db/jdbc_postgres.rb

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@
44
require 'jdbc/postgres' # driver not loaded for plain JDBC
55
Jdbc::Postgres::load_driver
66

7-
url = POSTGRES_CONFIG[:host].dup
8-
url << ":#{POSTGRES_CONFIG[:port]}" if POSTGRES_CONFIG[:port]
7+
url = POSTGRES_CONFIG[:url] || begin
8+
url_part = POSTGRES_CONFIG[:host].dup
9+
url_part << ":#{POSTGRES_CONFIG[:port]}" if POSTGRES_CONFIG[:port]
10+
"jdbc:postgresql://#{url_part}/#{POSTGRES_CONFIG[:database]}"
11+
end
912

1013
ActiveRecord::Base.establish_connection({
11-
:adapter => 'jdbc',
12-
:driver => 'org.postgresql.Driver',
13-
:url => "jdbc:postgresql://#{url}/#{POSTGRES_CONFIG[:database]}",
14+
:adapter => 'jdbc', :url => url, :driver => 'org.postgresql.Driver',
1415
:username => POSTGRES_CONFIG[:username],
1516
:password => POSTGRES_CONFIG[:password],
1617
:prepared_statements => ENV['PREPARED_STATEMENTS'] || ENV['PS']
1718
})
1819

19-
begin
20-
result = ActiveRecord::Base.connection.execute("SHOW server_version_num")
21-
PG_VERSION = result.first.first[1].to_i
22-
rescue
23-
PG_VERSION = 0
24-
end
20+
$LOADED_FEATURES << 'db/postgres.rb' # we're running tests that require this

test/db/postgres.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,3 @@
22
require 'db/postgres_config'
33

44
ActiveRecord::Base.establish_connection(POSTGRES_CONFIG)
5-
6-
begin
7-
result = ActiveRecord::Base.connection.execute("SHOW server_version_num")
8-
PG_VERSION = result.first.first[1].to_i
9-
rescue
10-
PG_VERSION = 0
11-
end

test/db/postgresql/native_types_test.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
require 'db/postgres'
22

3-
class PostgresNativeTypesTest < Test::Unit::TestCase
3+
class PostgreSQLNativeTypesTest < Test::Unit::TestCase
4+
5+
begin
6+
result = ActiveRecord::Base.connection.execute("SHOW server_version_num")
7+
PG_VERSION = result.first.values[0].to_i
8+
rescue
9+
PG_VERSION = 0
10+
end
411

512
class CustomersMigration < ActiveRecord::Migration
613
def self.up

0 commit comments

Comments
 (0)