Skip to content

Commit

Permalink
Add workaround for loading JDBC adapter in JRuby
Browse files Browse the repository at this point in the history
  • Loading branch information
nertzy committed Sep 13, 2013
1 parent 60dae3f commit 3bcd341
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
end

begin
require "pg"
error_class = PGError
rescue
begin
require "arjdbc/jdbc/core_ext"
if defined? JRUBY_VERSION
# Can't require 'activerecord-jdbcpostgresql-adapter' until
# https://github.com/jruby/activerecord-jdbc-adapter/pull/463
# is resolved
require 'arjdbc'
require 'arjdbc/postgresql'

error_class = ActiveRecord::JDBCError
rescue LoadError, StandardError
raise "I don't know what database adapter you're using, sorry."
else
require "pg"
error_class = PGError
end
end

Expand All @@ -35,15 +38,15 @@
connection = ActiveRecord::Base.connection
postgresql_version = connection.send(:postgresql_version)
connection.execute("SELECT 1")
rescue error_class => e
rescue error_class
at_exit do
puts "-" * 80
puts "Unable to connect to database. Please run:"
puts
puts " createdb pg_search_test"
puts "-" * 80
end
raise e
raise $!
end

if ENV["LOGGER"]
Expand Down

0 comments on commit 3bcd341

Please sign in to comment.