2019-02-26 11:55:34 -05:00
# frozen_string_literal: true
require_relative 'db_cleaner'
RSpec . configure do | config |
include DbCleaner
2021-07-27 11:09:49 -04:00
# Ensure the database is empty at the start of the suite run with :deletion strategy
# neither the sequence is reset nor the tables are vacuum, but this provides
# better I/O performance on machines with slower storage
2019-02-26 11:55:34 -05:00
config . before ( :suite ) do
setup_database_cleaner
2021-07-27 11:09:49 -04:00
DatabaseCleaner . clean_with ( :deletion )
2019-02-26 11:55:34 -05:00
end
2019-12-02 16:06:51 -05:00
config . append_after ( :context , :migration ) do
2021-09-10 11:11:12 -04:00
delete_from_all_tables! ( except : [ 'work_item_types' ] )
2019-12-02 16:06:51 -05:00
# Postgres maximum number of columns in a table is 1600 (https://github.com/postgres/postgres/blob/de41869b64d57160f58852eab20a27f248188135/src/include/access/htup_details.h#L23-L47).
# We drop and recreate the database if any table has more than 1200 columns, just to be safe.
2021-09-29 05:11:43 -04:00
if any_connection_class_with_more_than_allowed_columns?
recreate_all_databases!
2019-12-02 16:06:51 -05:00
end
end
2019-04-26 11:49:19 -04:00
config . around ( :each , :delete ) do | example |
self . class . use_transactional_tests = false
2019-02-26 11:55:34 -05:00
2019-04-26 11:49:19 -04:00
example . run
2019-02-26 11:55:34 -05:00
2019-04-26 11:49:19 -04:00
delete_from_all_tables! ( except : deletion_except_tables )
2021-08-19 11:10:29 -04:00
self . class . use_transactional_tests = true
2019-02-26 11:55:34 -05:00
end
2019-04-26 11:49:19 -04:00
config . around ( :each , :migration ) do | example |
self . class . use_transactional_tests = false
2019-02-26 11:55:34 -05:00
2019-04-26 11:49:19 -04:00
example . run
2019-02-26 11:55:34 -05:00
2021-09-10 11:11:12 -04:00
delete_from_all_tables! ( except : [ 'work_item_types' ] )
2021-08-19 11:10:29 -04:00
self . class . use_transactional_tests = true
2019-02-26 11:55:34 -05:00
end
end