DatabaseCleaner / database_cleaner

Strategies for cleaning databases in Ruby. Can be used to ensure a clean state for testing.
https://www.rubydoc.info/github/DatabaseCleaner/database_cleaner
MIT License
2.94k stars 484 forks source link

Fix docs about usage of only and except options #682

Closed oboxodo closed 3 years ago

oboxodo commented 3 years ago

The existing docs lead to non-working code at least with Ruby 2.7.

We need to either make the Array or the Hash explicit in order for it to work:

irb(main):026:0> DatabaseCleaner[:active_record].strategy = :truncation, only: ["users"]
Traceback (most recent call last):
SyntaxError ((irb):26: syntax error, unexpected tLABEL)
...].strategy = :truncation, only: ["users"]
...                          ^~~~~
irb(main):027:0> DatabaseCleaner[:active_record].strategy = [:truncation, only: ["users"]]
=> [:truncation, {:only=>["users"]}]
irb(main):028:0> DatabaseCleaner[:active_record].strategy = :truncation, {only: ["users"]}
=> [:truncation, {:only=>["users"]}]
codecov[bot] commented 3 years ago

Codecov Report

Merging #682 (22d4753) into main (a8cfc85) will not change coverage. The diff coverage is n/a.

:exclamation: Current head 22d4753 differs from pull request most recent head 58b25aa. Consider uploading reports for the commit 58b25aa to get more accurate results Impacted file tree graph

@@            Coverage Diff            @@
##              main      #682   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           19        19           
  Lines          674       674           
=========================================
  Hits           674       674           

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 a8cfc85...58b25aa. Read the comment docs.

viktorianer commented 3 years ago

For me, it worked this way to:

DatabaseCleaner[:active_record].strategy = :transaction
DatabaseCleaner.clean_with(:deletion, except: %w(templates))

Either one way or another, it is incorrectly documented and needs to be corrected!

botandrose commented 3 years ago

Thank you, @oboxodo!