Skip to content

Commit

Permalink
Setup DatabaseCleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
goulvench committed Feb 13, 2025
1 parent 2b45443 commit c00d4ca
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# that will avoid rails generators crashing because migrations haven't been run yet
# return unless Rails.env.test?
require "rspec/rails"
require "database_cleaner"

# Add additional requires below this line. Rails is not loaded until this point!

Expand Down Expand Up @@ -49,6 +50,20 @@
# You can uncomment this line to turn off ActiveRecord support entirely.
# config.use_active_record = false

# Setup Database cleaner to avoid state leaks between tests
config.before(:suite) do
DatabaseCleaner.clean_with :truncation, except: [:ar_internal_metadata]
end

config.before do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.start
end

config.append_after do
DatabaseCleaner.clean
end

# Feature-specific config
config.include Capybara::DSL, type: :feature
config.include Capybara::RSpecMatchers, type: :feature
Expand Down

0 comments on commit c00d4ca

Please sign in to comment.