debian-mirror-gitlab/spec/support/db_cleaner.rb

50 lines
1.3 KiB
Ruby
Raw Normal View History

2018-03-17 18:26:18 +05:30
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-09-02 18:07:02 +05:30
RSpec.configure do |config|
2018-03-17 18:26:18 +05:30
# Ensure all sequences are reset at the start of the suite run
2014-09-02 18:07:02 +05:30
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
2017-08-17 22:00:37 +05:30
config.append_after(:context) do
2018-03-17 18:26:18 +05:30
DatabaseCleaner.clean_with(:deletion, cache_tables: false)
2017-08-17 22:00:37 +05:30
end
2019-02-13 22:33:31 +05:30
config.before do
2014-09-02 18:07:02 +05:30
DatabaseCleaner.strategy = :transaction
end
2018-03-17 18:26:18 +05:30
config.before(:each, :js) do
2018-03-27 19:54:05 +05:30
DatabaseCleaner.strategy = :deletion, { cache_tables: false }
2014-09-02 18:07:02 +05:30
end
2018-03-17 18:26:18 +05:30
config.before(:each, :delete) do
2018-03-27 19:54:05 +05:30
DatabaseCleaner.strategy = :deletion, { cache_tables: false }
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
config.before(:each, :migration) do
2018-03-17 18:26:18 +05:30
DatabaseCleaner.strategy = :deletion, { cache_tables: false }
2017-09-10 17:25:29 +05:30
end
2019-02-13 22:33:31 +05:30
config.before do
2014-09-02 18:07:02 +05:30
DatabaseCleaner.start
end
2019-02-13 22:33:31 +05:30
config.append_after do
2014-09-02 18:07:02 +05:30
DatabaseCleaner.clean
end
end