diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fa51c05f4..89f378dc9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -60,6 +60,9 @@ jobs: BUNDLE_GEMFILE: ${{ matrix.gemfile }} EXPERIMENTAL: ${{ matrix.experimental }} JRUBY_OPTS: --debug + # Ruby version > 2.3 needs host 127.0.0.1 for GitHub Action to find Postgres. + # Ruby version <= 2.3 will throw random error from C if host is provided. + PG_HOST: ${{ matrix.ruby > 2.3 && '127.0.0.1' || null }} # workaround to ternary operator steps: - uses: actions/checkout@v3 - name: Setup ImageMagick policy diff --git a/spec/support/activerecord.rb b/spec/support/activerecord.rb index 73a4d308e..ea5bf1b7c 100644 --- a/spec/support/activerecord.rb +++ b/spec/support/activerecord.rb @@ -9,7 +9,6 @@ # Change this if PG is unavailable dbconfig = { - :host => '127.0.0.1', :adapter => 'postgresql', :database => 'carrierwave_test', :encoding => 'utf8', @@ -17,6 +16,8 @@ :password => 'postgres' } +dbconfig[:host] = ENV['PG_HOST'] unless ENV['PG_HOST'].nil? + database = dbconfig.delete(:database) ActiveRecord::Base.establish_connection(dbconfig.merge(database: "template1"))