<commit_before>RSpec.describe 'metasploit-cache', :content do
  def db_content_load
    db_content_purge
    db_content_load_schema

    expect(Metasploit::Cache::Module::Class::Name.count).to eq(0)
  end

  def db_content_load_schema
    begin
      ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations.fetch('content'))
      ActiveRecord::Schema.verbose = false
      db_schema_load
    ensure
      ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations.fetch('test'))
    end
  end

  def db_content_purge
    ActiveRecord::Tasks::DatabaseTasks.purge ActiveRecord::Base.configurations.fetch('content')
  end

  def db_schema_load
    file = File.join('spec', 'dummy', 'db', 'schema.rb')

    if File.exist?(file)
      load(file)
    else<commit_msg>Set DatabaseTasks.root so purge works<commit_after>RSpec.describe 'metasploit-cache', :content do
  def db_content_load
    db_content_purge
    db_content_load_schema

    expect(Metasploit::Cache::Module::Class::Name.count).to eq(0)
  end

  def db_content_load_schema
    begin
      ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations.fetch('content'))
      ActiveRecord::Schema.verbose = false
      db_schema_load
    ensure
      ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations.fetch('test'))
    end
  end

  def db_content_purge
    ActiveRecord::Tasks::DatabaseTasks.root = Metasploit::Cache::Engine.root

    ActiveRecord::Tasks::DatabaseTasks.purge ActiveRecord::Base.configurations.fetch('content')
  end

  def db_schema_load
    file = File.join('spec', 'dummy', 'db', 'schema.rb')

    if File.exist?(file)
      load(file)
    else
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.001182033096926714, 'mean_word_length': 4.532679738562091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4900386', 'n_tokens_mistral': 534, 'n_tokens_neox': 517, 'n_words': 81}