Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

url_allowlist only works against DATABASE_URL

Abierto
#684 1 comentario 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
postgresql, rails, ruby

Línea de trabajo

Comienza rastreando el manejo de url_allowlist por parte de Safeguard y cómo se invocan los cleaners; después, compáralo con la conexión de ActiveRecord de database_cleaner-active_record. Se considera terminado cuando safeguard comprueba la conexión que realmente se utiliza desde database.yml o DATABASE_URL en lugar de depender únicamente de ENV['DATABASE_URL'], incluso cuando esa variable no está definida.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

I debated filing this against database_cleaner-active_record, but after digging in a bit I think it would need a more comprehensive fix.

I have a Rails app running in a Docker stack, where under test, the database is configured the old-fashioned way in database.yml rather than with ENV['DATABASE_URL'] -- or rather, both are supported, but if DATABASE_URL isn't set, it falls back to a hard-coded value.

test:
  url: <%= ENV['DATABASE_URL'] ||'postgres://root:root@db/framework-test?pool=5' %>

I wanted a safeguard that would work both with the Docker stack in CI, or for a developer setting up a test database locally or on some other database server, so I assumed I had to set url_allowlist. My first attempt was this lambda:

  DatabaseCleaner.url_allowlist = [
    ->(url) { URI.parse(url).path.end_with?('framework-test') }
  ]

This blows up, though, because the URL that gets passed here is ENV['DATABASE_URL'], and URI.parse(nil) fails.

My next concern was that DatabaseCleaner would truncate the database at ENV['DATABASE_URL'] (if it exists) rather than the one ActiveRecord is actually using in tests. Thankfully database_cleaner-active_record is smarter than that, and it's using the ActiveRecord connection.

But it seems like if that's how it actually works, Safeguard should somehow hook into that, rather than relying on ENV['DATABASE_URL']. Maybe instead of running once before all cleaners, it should be run per-cleaner, and the cleaner implementations should be responsible for providing the URL they're actually using?

Lenguaje dominante
Ruby
Estrellas
3k
Forks
485
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

  • Incluye un Dockerfile o un archivo de Docker Compose
  • Sin plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de DatabaseCleaner/database_cleaner

Todos los issues de DatabaseCleaner/database_cleaner

Issues similares

Más issues de Ruby

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.