2018-01-22 10:22:03 -05:00
|
|
|
require 'database_cleaner/active_record/deletion'
|
|
|
|
|
|
|
|
module FakeInformationSchema
|
|
|
|
# Work around a bug in DatabaseCleaner when using the deletion strategy:
|
|
|
|
# https://github.com/DatabaseCleaner/database_cleaner/issues/347
|
|
|
|
#
|
|
|
|
# On MySQL, if the information schema is said to exist, we use an inaccurate
|
|
|
|
# row count leading to some tables not being cleaned when they should
|
|
|
|
def information_schema_exists?(_connection)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
DatabaseCleaner::ActiveRecord::Deletion.prepend(FakeInformationSchema)
|
|
|
|
|
2014-06-05 14:21:28 -04:00
|
|
|
RSpec.configure do |config|
|
2018-01-17 06:30:25 -05:00
|
|
|
# Ensure all sequences are reset at the start of the suite run
|
2014-06-07 04:09:56 -04:00
|
|
|
config.before(:suite) do
|
|
|
|
DatabaseCleaner.clean_with(:truncation)
|
|
|
|
end
|
2014-06-06 02:01:17 -04:00
|
|
|
|
2017-02-17 10:19:39 -05:00
|
|
|
config.append_after(:context) do
|
2018-01-17 06:30:25 -05:00
|
|
|
DatabaseCleaner.clean_with(:deletion, cache_tables: false)
|
2017-02-17 10:19:39 -05:00
|
|
|
end
|
|
|
|
|
2014-06-07 04:09:56 -04:00
|
|
|
config.before(:each) do
|
2014-06-06 02:01:17 -04:00
|
|
|
DatabaseCleaner.strategy = :transaction
|
|
|
|
end
|
|
|
|
|
2017-08-23 05:28:52 -04:00
|
|
|
config.before(:each, :js) do
|
2018-02-23 17:12:54 -05:00
|
|
|
DatabaseCleaner.strategy = :deletion, { cache_tables: false }
|
2014-06-07 04:09:56 -04:00
|
|
|
end
|
|
|
|
|
2018-01-17 06:30:25 -05:00
|
|
|
config.before(:each, :delete) do
|
2018-02-23 17:12:54 -05:00
|
|
|
DatabaseCleaner.strategy = :deletion, { cache_tables: false }
|
2016-10-11 08:25:17 -04:00
|
|
|
end
|
|
|
|
|
2017-08-16 08:07:17 -04:00
|
|
|
config.before(:each, :migration) do
|
2018-01-17 06:30:25 -05:00
|
|
|
DatabaseCleaner.strategy = :deletion, { cache_tables: false }
|
2017-05-26 08:46:45 -04:00
|
|
|
end
|
|
|
|
|
2014-06-07 04:09:56 -04:00
|
|
|
config.before(:each) do
|
|
|
|
DatabaseCleaner.start
|
|
|
|
end
|
|
|
|
|
2016-09-04 12:59:00 -04:00
|
|
|
config.append_after(:each) do
|
2014-06-07 04:09:56 -04:00
|
|
|
DatabaseCleaner.clean
|
2012-08-23 05:19:40 -04:00
|
|
|
end
|
|
|
|
end
|