Module: TestSupport::DB::Cleaning
- Defined in:
- lib/hanami/minitest/generators/templates/support_db_cleaning.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.all_databases ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hanami/minitest/generators/templates/support_db_cleaning.rb', line 57 def all_databases @all_databases ||= begin slices = [Hanami.app] + Hanami.app.slices.with_nested slices.each_with_object([]) { |slice, dbs| next unless slice.key?("db.rom") dbs.concat slice["db.rom"].gateways.values.map(&:connection) }.uniq end end |
.included(base) ⇒ Object
8 9 10 |
# File 'lib/hanami/minitest/generators/templates/support_db_cleaning.rb', line 8 def self.included(base) base.extend(ClassMethods) end |
.once ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/hanami/minitest/generators/templates/support_db_cleaning.rb', line 48 def once @cleaned_once ||= false return if @cleaned_once yield @cleaned_once = true end |
Instance Method Details
#setup ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hanami/minitest/generators/templates/support_db_cleaning.rb', line 20 def setup # Clean all databases before the first test Cleaning.once do Cleaning.all_databases.each do |db| DatabaseCleaner[:sequel, db: db].clean_with :truncation, except: ["schema_migrations"] end end use_truncation = self.class.instance_variable_get(:@db_cleaning_with_truncation) strategy = use_truncation ? :truncation : :transaction Cleaning.all_databases.each do |db| DatabaseCleaner[:sequel, db: db].strategy = strategy DatabaseCleaner[:sequel, db: db].start end super end |
#teardown ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/hanami/minitest/generators/templates/support_db_cleaning.rb', line 39 def teardown Cleaning.all_databases.each do |db| DatabaseCleaner[:sequel, db: db].clean end super end |