Skip to content

Commit

Permalink
Add database-cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
lujanfernaud committed Jul 20, 2018
1 parent a9403b7 commit d4caa26
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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!
Expand Down
13 changes: 13 additions & 0 deletions test/support/database_cleaner_support.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/support/support.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
11 changes: 9 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -43,15 +48,15 @@ class ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
include FactoryBot::Syntax::Methods

include DatabaseCleanerSupport

include ApplicationHelper
include EventsHelper

include StubsSupport
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
Expand All @@ -63,6 +68,8 @@ class ActiveSupport::TestCase
fixtures :all
include FactoryBot::Syntax::Methods

include DatabaseCleanerSupport

include StubsSupport
include TestCaseSupport
include UserSupport
Expand Down

0 comments on commit d4caa26

Please sign in to comment.