diff --git a/Gemfile b/Gemfile index 56c9d66..46cf5a8 100644 --- a/Gemfile +++ b/Gemfile @@ -60,6 +60,7 @@ group :test do gem 'faker' gem 'simplecov', require: false gem 'test_after_commit' # TODO remove when moving to rails 5 + gem 'database_cleaner' end # Use ActiveModel has_secure_password diff --git a/Gemfile.lock b/Gemfile.lock index 5493a50..7ed891e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -54,6 +54,7 @@ GEM coffee-script-source execjs coffee-script-source (1.9.1.1) + database_cleaner (1.5.1) diff-lcs (1.2.5) docile (1.1.5) elasticsearch (1.0.8) @@ -273,6 +274,7 @@ DEPENDENCIES awesome_print capybara coffee-rails + database_cleaner elasticsearch elasticsearch-dsl elasticsearch-model diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index a555fc5..02f950a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -33,7 +33,7 @@ RSpec.configure do |config| # 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 + config.use_transactional_fixtures = false # RSpec Rails can automatically mix in different behaviours to your tests # based on their file location, for example enabling you to call `get` and diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb new file mode 100644 index 0000000..46147b0 --- /dev/null +++ b/spec/support/database_cleaner.rb @@ -0,0 +1,22 @@ +RSpec.configure do |config| + config.before(:suite) do + DatabaseCleaner.clean_with(:truncation) + end + + config.before(:each) do + DatabaseCleaner.strategy = :transaction + end + + config.before(:each, type: :feature) do + DatabaseCleaner.strategy = :truncation + end + + config.before(:each) do + DatabaseCleaner.start + end + + config.append_after(:each) do + DatabaseCleaner.clean + end + +end