diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 9813e15..316812e 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -13,20 +13,32 @@ jobs: BUNDLE_JOBS: 4 BUNDLE_RETRY: 3 BUNDLE_GEMFILE: ${{ matrix.gemfile }} - DATABASE_URL: postgres://postgres:postgres@localhost:5432 + POSTGRES_URL: postgres://postgres:postgres@localhost:5432 + DB: ${{ matrix.db }} + DB_NAME: slotted_counters_test CI: true strategy: fail-fast: false matrix: ruby: ["3.0"] gemfile: ["gemfiles/rails7.gemfile"] + db: ["sqlite"] include: - ruby: "2.7" gemfile: "gemfiles/rails6.gemfile" + db: "postgres" - ruby: "3.1" gemfile: "gemfiles/railsmaster.gemfile" + db: "postgres" - ruby: "3.0" gemfile: "gemfiles/rails7.gemfile" + db: "postgres" + - ruby: "2.7" + gemfile: "gemfiles/rails6.gemfile" + db: "sqlite" + - ruby: "3.1" + gemfile: "gemfiles/railsmaster.gemfile" + db: "sqlite" services: postgres: image: postgres:14 diff --git a/spec/support/active_record_init.rb b/spec/support/active_record_init.rb index 39d2244..aa278ba 100644 --- a/spec/support/active_record_init.rb +++ b/spec/support/active_record_init.rb @@ -1,22 +1,27 @@ # frozen_string_literal: true -connection_params = - if ENV.key?("DATABASE_URL") - {"url" => ENV["DATABASE_URL"]} - else - { - "host" => ENV.fetch("DB_HOST", "localhost"), - "username" => ENV.fetch("DB_USER", "postgres"), - "port" => ENV.fetch("DB_PORT", "9339").to_i - } +DB_CONFIG = + if ENV["DB"] == "postgres" + require "active_record/database_configurations" + url = ENV.fetch("POSTGRES_URL") + + config = ActiveRecord::DatabaseConfigurations::UrlConfig.new( + "test", + "primary", + url, + {"database" => ENV.fetch("DB_NAME", "slotted_counters_test")} + ) + config.respond_to?(:configuration_hash) ? config.configuration_hash : config.config + elsif ENV["DB"] == "sqlite" + # Make sure we don't have a DATABASE_URL set (it can be used by libs, e.g., database_cleaner) + ENV.delete("DATABASE_URL") if ENV["DATABASE_URL"] + + {adapter: "sqlite3", database: ":memory:"} end -ActiveRecord::Base.establish_connection( - { - "adapter" => "postgresql", - "database" => "slotted_counters_test" - }.merge(connection_params) -) +$stdout.puts "⚙️ Using #{DB_CONFIG[:adapter]} adapter for a database" + +ActiveRecord::Base.establish_connection(**DB_CONFIG) ActiveRecord::Schema.define do create_table "views", force: :cascade do |t|