Sha256: 86edc2059d7f3f7c2b410afaf06df852e2c5ff880caeebd9f82cf9995b711953
Contents?: true
Size: 880 Bytes
Versions: 6
Compression:
Stored size: 880 Bytes
Contents
module TestData class TruncatesTestData def initialize @config = TestData.config @statistics = TestData.statistics end def call connection.disable_referential_integrity do connection.execute("TRUNCATE TABLE #{tables_to_truncate.map { |t| connection.quote_table_name(t) }.join(", ")} #{"CASCADE" unless @config.truncate_these_test_data_tables.present?}") end @statistics.count_truncate! end private def tables_to_truncate if @config.truncate_these_test_data_tables.present? @config.truncate_these_test_data_tables else @tables_to_truncate ||= IO.foreach(@config.data_dump_path).grep(/^INSERT INTO/) { |line| line.match(/^INSERT INTO ([^\s]+)/)&.captures&.first }.compact.uniq end end def connection ActiveRecord::Base.connection end end end
Version data entries
6 entries across 6 versions & 1 rubygems