secondbase icon indicating copy to clipboard operation
secondbase copied to clipboard

Document DatabaseCleaner Examples

Open metaskills opened this issue 9 years ago • 5 comments

I think we can document some simple examples using SecondBase.on_base { ... } for test setup/teardown when using database cleaner. https://github.com/DatabaseCleaner/database_cleaner/tree/master/lib/database_cleaner/active_record

metaskills avatar Jan 06 '16 16:01 metaskills

cc @sarsena

metaskills avatar Jan 06 '16 16:01 metaskills

@metaskills that would be awesome I am using DatabaseCleaner, and https://github.com/grosser/parallel_tests

sbrady avatar Aug 29 '16 16:08 sbrady

Any examples on how to do this?

carlows avatar Sep 21 '17 17:09 carlows

Here is an example I have in a Rails v5.1 app.

require 'database_cleaner'
DatabaseCleaner.clean_with :truncation, except: [ActiveRecord::InternalMetadata.table_name]
DatabaseCleaner.clean

require 'factory_girl'
include FactoryGirl::Syntax::Methods
include NamedSeeds::DSL
begin
  FactoryGirl.find_definitions
rescue
  false
end

metaskills avatar Sep 25 '17 11:09 metaskills

This is at the top of db/seeds.rb file

metaskills avatar Sep 25 '17 11:09 metaskills