<commit_before>ENV["RAILS_ENV"] ||= "test"

require 'dummy/config/application'
require 'rspec/rails'
require 'database_cleaner'
require 'marty_rspec'

Dummy::Application.initialize! unless Dummy::Application.initialized?

ActiveRecord::Migrator.migrate File.expand_path("../../db/migrate/", __FILE__)
ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)

Dir[Rails.root.join("../support/**/*.rb")].each { |f| require f }

CLASSES_TO_EXCLUDE_FROM_SHARED = ["Marty::Log"]
class ActiveRecord::Base
  mattr_accessor :shared_connection
  class << self
    alias_method :orig_connection, :connection
  end
  def self.clear_connection
    @@shared_connection = nil
  end

  clear_connection

  def self.connection
    CLASSES_TO_EXCLUDE_FROM_SHARED.include?(model_name) ? orig_connection :
      @@shared_connection || retrieve_connection
  end

  def self.reset_shared_connection
    @@shared_connection = retrieve_connection
  end
end

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: { args: %w[headless disable-gpu] }
  )

  Capybara::Selenium::Driver.new app,
                                 browser: :chrome,
                                 desired_capabilities: capabilities
end

Capybara.javascript_driver = :headless_chrome

ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

RSpec.configure do |config|
  config.include DelayedJobHelpers
  config.include CleanDbHelpers<commit_msg>added environment variable check for headless chrome<commit_after>ENV["RAILS_ENV"] ||= "test"

require 'dummy/config/application'
require 'rspec/rails'
require 'database_cleaner'
require 'marty_rspec'

Dummy::Application.initialize! unless Dummy::Application.initialized?

ActiveRecord::Migrator.migrate File.expand_path("../../db/migrate/", __FILE__)
ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)

Dir[Rails.root.join("../support/**/*.rb")].each { |f| require f }

CLASSES_TO_EXCLUDE_FROM_SHARED = ["Marty::Log"]
class ActiveRecord::Base
  mattr_accessor :shared_connection
  class << self
    alias_method :orig_connection, :connection
  end
  def self.clear_connection
    @@shared_connection = nil
  end

  clear_connection

  def self.connection
    CLASSES_TO_EXCLUDE_FROM_SHARED.include?(model_name) ? orig_connection :
      @@shared_connection || retrieve_connection
  end

  def self.reset_shared_connection
    @@shared_connection = retrieve_connection
  end
end

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: { args: %w[headless disable-gpu] }
  )

  Capybara::Selenium::Driver.new app,
                                 browser: :chrome,
                                 desired_capabilities: capabilities
end

Capybara.javascript_driver = ENV['HEADLESS'] == 'true' ? :headless_chrome : :chrome

ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

RSpec.configure do |config|
  config.include DelayedJobHelpers
  config.include CleanDbHelpers
{'fraction_non_alphanumeric': 0.11151187255785994, 'fraction_numerical': 0.0, 'mean_word_length': 4.593277310924369, 'pattern_counts': {'":': 0, '<': 7, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '309592', 'n_tokens_mistral': 1050, 'n_tokens_neox': 1034, 'n_words': 188}