database_rewinder icon indicating copy to clipboard operation
database_rewinder copied to clipboard

Share solution

Open Paxa opened this issue 11 years ago • 3 comments

When I change to database rewinder our tests become slower, because in many cases we used transaction strategy.

Here is solution that worked for us: Use DatabaseRewinder only for capybara+js examples, for others - DatabaseCleaner with db transactions

RSpec.configure do |config|
  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseRewinder.clean_all
  end

  config.before(:each) do |example|
    if example.metadata[:js]
      # nothing
    else
      DatabaseCleaner.start
    end
  end

  config.after(:each) do |example|
    if example.metadata[:js]
      DatabaseRewinder.clean
    else
      DatabaseCleaner.clean
      DatabaseRewinder.cleaners.each {|c| c.send(:reset) }
    end
  end
end

Paxa avatar Apr 07 '15 05:04 Paxa

Nice tip. I'm trying this out in y project as well, have best things out both gems here ;)

skatkov avatar Jul 28 '15 10:07 skatkov

What does the DatabaseRewinder.cleaners.each {|c| c.send(:reset) } line do?

machty avatar Jul 10 '17 16:07 machty

Oh does it reset the tracked data as to which tables were mutated?

machty avatar Jul 10 '17 16:07 machty