Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow_remote_database_url not working as expected #668

Open
wout opened this issue Oct 11, 2020 · 2 comments
Open

allow_remote_database_url not working as expected #668

wout opened this issue Oct 11, 2020 · 2 comments

Comments

@wout
Copy link

wout commented Oct 11, 2020

  • ruby: 2.7.2
  • rails: 6.0.3.4
  • database_cleaner: 1.8.5
  • database_cleaner-active_record: 1.8.0

I'm running Rails in development in a Dockerized environment. One of the configured Docker Compose services is a container to run commands (e.g. rails, rake, ...) and its RAILS_ENV is development. If I accidentally run rspec in that particular container, my development database gets cleaned, which is not what I want.

I tried configuring DatabaseCleaner.url_whitelist to include the full URL to the test database. For example:

DatabaseCleaner.url_whitelist = %w[postgres://postgres:postgres@postgres:5432/my_app_test]

But it looks like only base URLs are considered.

Then I tried allowing remote URLs for the test environment alone by adding the following line at the top of support/database_cleaner.rb:

DatabaseCleaner.allow_remote_database_url = Rails.env.test?

But that's ignored for some reason. I checked if Rails.env.test? is false at that point, and it is.

So now I've replaced that line with:

raise StandardError, "Database cleaner expected 'test' environment" unless Rails.env.test?

Which works. But isn't allow_remote_database_url supposed to do the same? Or am I missing something crucial?

@tmaier
Copy link

tmaier commented Feb 1, 2021

Re DatabaseCleaner.url_allowlist: This should support regex as well. See README

@takamario
Copy link

I tried with rspec by setting ENV['RAILS_ENV'] ||= 'test' in spec/rails_helper.rb, but
77dece1 caused Rails.env.test? to return false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants