From f13c0e1dca74d6274f2a4aea6c2e9ff3fc31313e Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 12 Apr 2023 14:23:09 +1000 Subject: [PATCH] Bring all Rspec config for database cleaning together --- spec/base_spec_helper.rb | 18 ++++++++++++++++++ spec/spec_helper.rb | 16 ---------------- spec/system/support/cuprite_setup.rb | 3 --- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/spec/base_spec_helper.rb b/spec/base_spec_helper.rb index 478b95f3cd..6696ed7639 100644 --- a/spec/base_spec_helper.rb +++ b/spec/base_spec_helper.rb @@ -57,6 +57,24 @@ RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + # + # Setting this to true keeps the database clean by rolling back any changes. + config.use_transactional_fixtures = true + + # Some tests don't work within a transaction. Then we use DatabaseCleaner. + config.before(:each, concurrency: true) do + config.use_transactional_fixtures = false + DatabaseCleaner.strategy = :deletion, { except: ['spree_countries', 'spree_states'] } + DatabaseCleaner.start + end + config.after(:each, concurrency: true) do + DatabaseCleaner.clean + config.use_transactional_fixtures = true + end + # If true, the base class of anonymous controllers will be inferred # automatically. This will be the default behavior in future versions of # rspec-rails. diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ff7b3d6889..da264f58e3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,17 +4,6 @@ require 'base_spec_helper' require 'database_cleaner' RSpec.configure do |config| - # DatabaseCleaner - config.before(:each, concurrency: true) do - config.use_transactional_fixtures = false - DatabaseCleaner.strategy = :deletion, { except: ['spree_countries', 'spree_states'] } - DatabaseCleaner.start - end - config.after(:each, concurrency: true) do - DatabaseCleaner.clean - config.use_transactional_fixtures = true - end - # Precompile Webpacker assets (once) when starting the suite. The default setup can result # in the assets getting compiled many times throughout the build, slowing it down. config.before :suite do @@ -24,11 +13,6 @@ RSpec.configure do |config| # Fix encoding issue in Rails 5.0; allows passing empty arrays or hashes as params. config.before(:each, type: :controller) { @request.env["CONTENT_TYPE"] = 'application/json' } - # If you're not using ActiveRecord, or you'd prefer not to run each of your - # examples within a transaction, remove the following line or assign false - # instead of true. - config.use_transactional_fixtures = true - # You can use `rspec -n` to run only failed specs. config.example_status_persistence_file_path = "tmp/rspec-status.txt" end diff --git a/spec/system/support/cuprite_setup.rb b/spec/system/support/cuprite_setup.rb index dd50fac14b..bdb7ba433e 100644 --- a/spec/system/support/cuprite_setup.rb +++ b/spec/system/support/cuprite_setup.rb @@ -33,9 +33,6 @@ RSpec.configure do |config| config.prepend_before(:each, type: :system) { driven_by :cuprite } - # System tests use transactional fixtures instead of DatabaseCleaner - config.use_transactional_fixtures = true - # Make sure url helpers in mailers use the Capybara server host. config.around(:each, type: :system) do |example| original_host = Rails.application.default_url_options[:host]