diff --git a/Gemfile b/Gemfile index da072122..30da9e2c 100644 --- a/Gemfile +++ b/Gemfile @@ -68,6 +68,7 @@ group :development, :test do end group :test do + gem 'database_cleaner', '~> 1.7' gem 'mocha', '~> 1.5' gem 'capybara', '~> 2.14' gem 'capybara-webkit', '~> 1.15' diff --git a/Gemfile.lock b/Gemfile.lock index 3297b558..b4edc4c6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -128,6 +128,7 @@ GEM crack (0.4.3) safe_yaml (~> 1.0.0) crass (1.0.4) + database_cleaner (1.7.0) debug_inspector (0.0.3) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) @@ -453,6 +454,7 @@ DEPENDENCIES cloudinary (~> 1.9, >= 1.9.1) coffee-rails (~> 4.2) country_select (~> 3.1, >= 3.1.1) + database_cleaner (~> 1.7) devise (~> 4.4, >= 4.4.3) factory_bot_rails (~> 4.10) faker! diff --git a/test/support/database_cleaner_support.rb b/test/support/database_cleaner_support.rb new file mode 100644 index 00000000..1c81b17c --- /dev/null +++ b/test/support/database_cleaner_support.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module DatabaseCleanerSupport + def before_setup + super + DatabaseCleaner.start + end + + def after_teardown + DatabaseCleaner.clean + super + end +end diff --git a/test/support/support.rb b/test/support/support.rb index 51857c22..fba44dcd 100644 --- a/test/support/support.rb +++ b/test/support/support.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative "database_cleaner_support" + require_relative "stubs_support" require_relative "user_support" require_relative "integration_support" diff --git a/test/test_helper.rb b/test/test_helper.rb index 39b5f0c5..7e97cfe7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -10,6 +10,11 @@ require 'mocha/minitest' require 'support/support' +require 'database_cleaner' + +DatabaseCleaner.clean_with :truncation +DatabaseCleaner.strategy = :transaction + require 'capybara/rails' require 'capybara/minitest' @@ -43,6 +48,8 @@ class ActionDispatch::IntegrationTest include Devise::Test::IntegrationHelpers include FactoryBot::Syntax::Methods + include DatabaseCleanerSupport + include ApplicationHelper include EventsHelper @@ -50,8 +57,6 @@ class ActionDispatch::IntegrationTest include IntegrationSupport include UserSupport - # Reset sessions and driver between tests - # Use super wherever this method is redefined in your individual test classes def teardown Capybara.reset_sessions! Capybara.use_default_driver @@ -63,6 +68,8 @@ class ActiveSupport::TestCase fixtures :all include FactoryBot::Syntax::Methods + include DatabaseCleanerSupport + include StubsSupport include TestCaseSupport include UserSupport