<commit_before>require 'test_helper'
require 'temp_table_test_case'

ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"

# Set up transactional tests
class ActiveSupport::TestCase
  include ActiveRecord::TestFixtures
end

class DeepPreloaderTest < ActiveSupport::TestCase
  include TemporaryTableTestCase

  def test_that_it_has_a_version_number
    refute_nil ::DeepPreloader::VERSION
  end

  def test_parse_hash_spec
    spec          = { a: [:b, { c: :d, e: nil }]}
    parsed_spec   = DeepPreloader::Spec.parse(spec)
    expected_spec = DeepPreloader::Spec.new(a: DeepPreloader::Spec.new(b: nil, c: DeepPreloader::Spec.new(d: nil), e: nil))

    assert_equal(expected_spec, parsed_spec)
  end

  def test_parse_polymorphic_hash_spec
    create_test_model(:model, ->(t){}){}

    parsed_spec   = DeepPreloader::Spec.parse(a: DeepPreloader::PolymorphicSpec.parse(Model => { b: :c }))

    expected_spec = DeepPreloader::Spec.new(a: DeepPreloader::PolymorphicSpec.new(Model => DeepPreloader::Spec.new(b: DeepPreloader::Spec.new(c: nil))))

    assert_equal(expected_spec, parsed_spec)
  end

  def test_preload_belongs_to
    create_test_model(:parent, ->(t){ t.references :child }) do
      belongs_to :child, inverse_of: :parent
    end
    create_test_model(:child, ->(t){ }) do
      has_one :parent, inverse_of: :child
    end
<commit_msg>Update test for "Polymorphic specs are keyed by model class name, not class"<commit_after>require 'test_helper'
require 'temp_table_test_case'

ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"

# Set up transactional tests
class ActiveSupport::TestCase
  include ActiveRecord::TestFixtures
end

class DeepPreloaderTest < ActiveSupport::TestCase
  include TemporaryTableTestCase

  def test_that_it_has_a_version_number
    refute_nil ::DeepPreloader::VERSION
  end

  def test_parse_hash_spec
    spec          = { a: [:b, { c: :d, e: nil }]}
    parsed_spec   = DeepPreloader::Spec.parse(spec)
    expected_spec = DeepPreloader::Spec.new(a: DeepPreloader::Spec.new(b: nil, c: DeepPreloader::Spec.new(d: nil), e: nil))

    assert_equal(expected_spec, parsed_spec)
  end

  def test_parse_polymorphic_hash_spec
    create_test_model(:model, ->(t){}){}

    parsed_spec   = DeepPreloader::Spec.parse(a: DeepPreloader::PolymorphicSpec.parse("Model" => { b: :c }))

    expected_spec = DeepPreloader::Spec.new(a: DeepPreloader::PolymorphicSpec.new("Model" => DeepPreloader::Spec.new(b: DeepPreloader::Spec.new(c: nil))))

    assert_equal(expected_spec, parsed_spec)
  end

  def test_preload_belongs_to
    create_test_model(:parent, ->(t){ t.references :child }) do
      belongs_to :child, inverse_of: :parent
    end
    create_test_model(:child, ->(t){ }) do
      has_one :parent, inverse_of: :child
    end

{'fraction_non_alphanumeric': 0.12025540971975877, 'fraction_numerical': 0.000709471443774388, 'mean_word_length': 5.064516129032258, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 13, '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': '2732903', 'n_tokens_mistral': 957, 'n_tokens_neox': 962, 'n_words': 190}