url_allowlist only works against DATABASE_URL
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
Direzione di ricerca
Inizia tracciando la gestione di url_allowlist da parte di Safeguard e il modo in cui vengono invocati i cleaners, quindi confrontala con la connessione ActiveRecord di database_cleaner-active_record. Il lavoro è completato quando safeguard controlla la connessione effettivamente utilizzata da database.yml o DATABASE_URL invece di affidarsi soltanto a ENV['DATABASE_URL'], anche quando questa variabile non è impostata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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?
- Lingua principale
- Ruby
- Stelle
- 3k
- Fork
- 485
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di DatabaseCleaner/database_cleaner
-
:transaction strategy: uncommitted data disappears after perform_enqueued_jobs on Rails ≥ 7.2Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 67/100
-
Cleaning of dev DBAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
-
Cannot truncate a table referenced in a foreign key constraint (ActiveRecord::StatementInvalid)Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
DatabaseCleaner/database_cleaner#717 · 5 commenti · 1 reazione ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
DatabaseCleaner/database_cleaner#716 · 2 commenti ·
Tutte le issue di DatabaseCleaner/database_cleaner
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
misa.G should not be definedApertadata error
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
riscv/riscv-unified-db#2648 ·
I maintainer di solito rispondono entro 1 giorno
-
P2 testing
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno