DatabaseCleaner / database_cleaner-active_record

Strategies for cleaning databases using ActiveRecord. Can be used to ensure a clean state for testing.
MIT License
64 stars 63 forks source link

Add support for aliased database configs #64

Closed aziflaj closed 2 years ago

aziflaj commented 3 years ago

Our database.yml looks like the following:

default: &default
  adapter: mysql2
  encoding: utf8
  reconnect: false
  somekey: someval

db1:
  <<: *default
  database: <%= ENV['DB_NAME'] %>

db2: 
  <<: *default
  database: db2name

When running the test suite, we were facing this issue:

Failure/Error:
  DatabaseCleaner[:active_record, db: :db1].
    clean_with(:deletion, except: %w[some_table])
Psych::BadAlias:
  Unknown alias: default

After some investigation, we found out that the line throwing the error was this one.

The changes in this PR fix said issue

codecov[bot] commented 3 years ago

Codecov Report

Merging #64 (9f76858) into main (c4d02ae) will not change coverage. The diff coverage is 100.00%.

:exclamation: Current head 9f76858 differs from pull request most recent head 13f4275. Consider uploading reports for the commit 13f4275 to get more accurate results Impacted file tree graph

@@            Coverage Diff            @@
##              main       #64   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           12        12           
  Lines          549       562   +13     
=========================================
+ Hits           549       562   +13     
Impacted Files Coverage Δ
lib/database_cleaner/active_record/base.rb 100.00% <100.00%> (ø)
spec/database_cleaner/active_record/base_spec.rb 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c4d02ae...13f4275. Read the comment docs.

aziflaj commented 2 years ago

Hey @etagwerker, can I get your 👀 on this one?

rdnewman commented 2 years ago

💯 Needed for Ruby 3.1 @etagwerker . Thanks @aziflaj!

aziflaj commented 2 years ago

I'm trying to bump this PR a bit. Can I get a review, and if this is a good addition to the gem, a merge please? cc @botandrose @etagwerker

DorianSwile commented 2 years ago

Hi, Thanks @aziflaj! for the fix, this is very useful I'm trying to bump this PR up too, cc @etagwerker @lubc

cyrilchampier commented 2 years ago

Hi @botandrose , you seems to be the last active contributor, are you still maintaining the gem?

cyrilchampier commented 2 years ago

Thanks @aziflaj and @etagwerker!

hsbt commented 1 year ago

@etagwerker Can you cut a new release from main branch? This issue is a block for upgrading after Ruby 3.1+ or Psych 4.0+. Thanks.