Skip to content

Commit

Permalink
Use different strategies according to gem version
Browse files Browse the repository at this point in the history
  • Loading branch information
ribose-jeffreylau committed Mar 3, 2021
1 parent 2391ea7 commit 96fcad9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions spec/support/db_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@

RSpec.configure do |config|
config.before(:suite) do

strategy = :truncation

unless WITHOUT_ACTIVE_RECORD
require "database_cleaner-active_record"
DatabaseCleaner[:active_record].strategy = :truncation
DatabaseCleaner[:active_record].strategy = strategy
end

# Since models are defined dynamically in specs, Database Cleaner is unable
# to list them and to determine collection names to be cleaned.
# Therefore, they are specified explicitly here.
unless WITHOUT_MONGOID
require "database_cleaner-mongoid"
DatabaseCleaner[:mongoid].strategy = :truncation, { only: "users" }

strategy =
Gem::Version.new(DatabaseCleaner::Mongoid::VERSION) >= Gem::Version.new("2.0.0") ?
:deletion : :truncation

DatabaseCleaner[:mongoid].strategy = strategy, { only: "users" }
end

DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.clean_with(strategy)
end

config.around(:each) do |example|
Expand Down

0 comments on commit 96fcad9

Please sign in to comment.