<commit_before>require File.join(File.dirname(__FILE__), 'setup')
require 'active_support/test_case'

module ReadFromSlave
  class Test
    class << self

      def setup
        setup_constants
        make_sqlite_config
        make_sqlite_connection
        load_models
        load(SCHEMA_ROOT + "/schema.rb")
        require 'test/unit'
        require File.join(File.dirname(__FILE__), '..', 'lib', 'read_from_slave')
      end

      def test_files
        glob("#{File.dirname(__FILE__)}/**/*_test.rb")
      end

      def test_model_files
        %w{course}
      end

      private

      def setup_constants
        set_constant('TEST_ROOT') { File.expand_path(File.dirname(__FILE__)) }
        set_constant('SCHEMA_ROOT') { TEST_ROOT + "/schema" }
      end

      def make_sqlite_config
        ActiveRecord::Base.configurations = {
            'rfs' => {
                :adapter => 'sqlite3',
                :database => 'test_db',
                :timeout => 5000,
                :slaves =>
                    {:primary_slave => 'primary_slave',
                     :slave_2 => 'slave_2'
                    }
            },
            'primary_slave' => {
                :adapter => 'sqlite3',
                :database => 'test_db',
                :timeout => 5000
            },
            'slave_2' => {
                :adapter => 'sqlite3',
                :database => 'test_db',
                :timeout => 5000
            }
        }
      end

      def load_models<commit_msg>Test that both specification methods work, symbols and keys for slaves<commit_after>require File.join(File.dirname(__FILE__), 'setup')
require 'active_support/test_case'

module ReadFromSlave
  class Test
    class << self

      def setup
        setup_constants
        make_sqlite_config
        make_sqlite_connection
        load_models
        load(SCHEMA_ROOT + "/schema.rb")
        require 'test/unit'
        require File.join(File.dirname(__FILE__), '..', 'lib', 'read_from_slave')
      end

      def test_files
        glob("#{File.dirname(__FILE__)}/**/*_test.rb")
      end

      def test_model_files
        %w{course}
      end

      private

      def setup_constants
        set_constant('TEST_ROOT') { File.expand_path(File.dirname(__FILE__)) }
        set_constant('SCHEMA_ROOT') { TEST_ROOT + "/schema" }
      end

      def make_sqlite_config
        ActiveRecord::Base.configurations = {
            'rfs' => {
                :adapter => 'sqlite3',
                :database => 'test_db',
                :timeout => 5000,
                :slaves =>
                    {'primary_slave' => 'primary_slave',
                     :slave_2 => 'slave_2'
                    }
            },
            'primary_slave' => {
                :adapter => 'sqlite3',
                :database => 'test_db',
                :timeout => 5000
            },
            'slave_2' => {
                :adapter => 'sqlite3',
                :database => 'test_db',
                :timeout => 5000
            }
        }
      end

      def load_models
{'fraction_non_alphanumeric': 0.11284046692607004, 'fraction_numerical': 0.011673151750972763, 'mean_word_length': 1.5142624286878565, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 33, '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': '7411296', 'n_tokens_mistral': 911, 'n_tokens_neox': 851, 'n_words': 159}