<commit_before>require 'helper'

class ElasticRecord::IndexTest < MiniTest::Test
  def test_copy
    copied = index.dup

    refute_equal copied.settings.object_id, index.settings.object_id
  end

  def test_alias_name
    with_test_suffix do
      assert_equal 'widgets_test', index.alias_name
    end
  end

  def test_disable
    index.disable!

    assert index.disabled
  end

  def test_enable
    index.disable!
    index.enable!

    refute index.disabled
  end

  def test_loading_from_source
    index.loading_from_source do
      assert index.load_from_source
    end
    refute index.load_from_source
  end

  def test_delegations_when_loading_from_source
    project = Project.new(name: 'Something')
    Project.elastic_index.index_record(project)

    found_project = Project.first
    assert_equal 'Something', found_project.name
    assert_equal 'Something', Project.find(found_project.id).name
  end

  private

    def index
      @index ||= ElasticRecord::Index.new(Widget)
    end

    def with_test_suffix
      ElasticRecord::Config.index_suffix = 'test'
      yield
    ensure
      ElasticRecord::Config.index_suffix = nil
    end
end<commit_msg>unnecessary method<commit_after>require 'helper'

class ElasticRecord::IndexTest < MiniTest::Test
  def test_copy
    copied = index.dup

    refute_equal copied.settings.object_id, index.settings.object_id
  end

  def test_alias_name
    ElasticRecord::Config.index_suffix = 'test'
    assert_equal 'widgets_test', index.alias_name
  ensure
    ElasticRecord::Config.index_suffix = nil
  end

  def test_disable
    index.disable!

    assert index.disabled
  end

  def test_enable
    index.disable!
    index.enable!

    refute index.disabled
  end

  def test_loading_from_source
    index.loading_from_source do
      assert index.load_from_source
    end
    refute index.load_from_source
  end

  def test_delegations_when_loading_from_source
    project = Project.new(name: 'Something')
    Project.elastic_index.index_record(project)

    found_project = Project.first
    assert_equal 'Something', found_project.name
    assert_equal 'Something', Project.find(found_project.id).name
  end

  private

    def index
      @index ||= ElasticRecord::Index.new(Widget)
    end
end
{'fraction_non_alphanumeric': 0.06728640991589199, 'fraction_numerical': 0.0, 'mean_word_length': 3.484126984126984, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5196333', 'n_tokens_mistral': 721, 'n_tokens_neox': 691, 'n_words': 145}