spec/support/database.rb in pg_search-2.1.4 vs spec/support/database.rb in pg_search-2.1.5

- old
+ new

@@ -1,39 +1,32 @@ # frozen_string_literal: true -if defined? JRUBY_VERSION +case RUBY_PLATFORM +when "java" require "activerecord-jdbc-adapter" - error_classes = [ActiveRecord::JDBCError] + ERROR_CLASS = ActiveRecord::JDBCError else require "pg" - error_classes = [PG::Error] + ERROR_CLASS = PG::Error end -error_classes << ActiveRecord::NoDatabaseError if defined? ActiveRecord::NoDatabaseError - begin - database_user = if ENV["TRAVIS"] - "postgres" - else - ENV["USER"] - end - - ActiveRecord::Base.establish_connection(:adapter => 'postgresql', - :database => 'pg_search_test', - :username => database_user, - :min_messages => 'warning') + ActiveRecord::Base.establish_connection(adapter: 'postgresql', + database: 'pg_search_test', + username: (ENV["TRAVIS"] ? "postgres" : ENV["USER"]), + min_messages: 'warning') connection = ActiveRecord::Base.connection connection.execute("SELECT 1") -rescue *error_classes => exception +rescue ERROR_CLASS, ActiveRecord::NoDatabaseError => e at_exit do puts "-" * 80 puts "Unable to connect to database. Please run:" puts puts " createdb pg_search_test" puts "-" * 80 end - raise exception + raise e end if ENV["LOGGER"] require "logger" ActiveRecord::Base.logger = Logger.new(STDOUT) @@ -43,16 +36,16 @@ connection = ActiveRecord::Base.connection extension = connection.execute "SELECT * FROM pg_catalog.pg_extension WHERE extname = '#{name}';" return unless extension.none? connection.execute "CREATE EXTENSION #{name};" -rescue StandardError => exception +rescue StandardError => e at_exit do puts "-" * 80 puts "Please install the #{name} extension" puts "-" * 80 end - raise exception + raise e end def install_extension_if_missing(name, query, expected_result) result = ActiveRecord::Base.connection.select_value(query) raise "Unexpected output for #{query}: #{result.inspect}" unless result.casecmp(expected_result).zero?