Skip to content

DB Migrations #27

Answered by guilleiguaran
kevinrobayna asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @kevinrobayna, this configuration worked for me in Rails project with RSpec:

First, looks like ActiveRecord connections are loaded before the before(:suite) block, so we need to create the container before, for reference I put the configuration just before the ActiveRecord::Migration.maintain_test_schema! generated by RSpec installer by default:

RSpec.configuration.add_setting :postgres_container, default: nil
RSpec.configuration.postgres_container = Testcontainers::PostgresContainer.new("postgres:15").start
ENV['DATABASE_URL'] = RSpec.configuration.postgres_container.database_url(database: 'pgblog_test')

Rails.application.load_tasks
Rake::Task['db:test:prepare'].invoke # require 'rak…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by guilleiguaran
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #17 on August 25, 2023 20:03.