diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 3d016a99..ed5afeb6 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,11 +1,11 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' -ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../config/environment', __dir__) +ENV["RAILS_ENV"] ||= "test" +require File.expand_path("../config/environment", __dir__) # Prevent database truncation if the environment is production -abort('The Rails environment is running in production mode!') if Rails.env.production? -require 'spec_helper' -require 'rspec/rails' -Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } +abort("The Rails environment is running in production mode!") if Rails.env.production? +require "spec_helper" +require "rspec/rails" +Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } # Add additional requires below this line. Rails is not loaded until this point! # Requires supporting ruby files with custom matchers and macros, etc, in @@ -27,6 +27,8 @@ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } # If you are not using ActiveRecord, you can remove this line. ActiveRecord::Migration.maintain_test_schema! +require "database_cleaner/active_record" + RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" @@ -55,4 +57,22 @@ RSpec.configure do |config| config.filter_rails_from_backtrace! # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") + # config.before(:each) do + # DatabaseCleaner.strategy = :deletion + # end + # config.append_after(:each) do + # DatabaseCleaner.clean + # end + config.before(:suite) do + DatabaseCleaner.strategy = :transaction + DatabaseCleaner.clean_with(:truncation) + end + + config.before(:each) do + DatabaseCleaner.start + end + + config.after(:each) do + DatabaseCleaner.clean + end end