<commit_before># frozen_string_literal: true

require "test_helper"

class TermTest < ActiveSupport::TestCase
  def vocabulary
    @vocabulary ||= gobierto_common_vocabularies(:animals)
  end

  def root_level_term
    @root_level_term ||= gobierto_common_terms(:mammal)
  end

  def dependent_level_term
    @dependent_level_term ||= gobierto_common_terms(:dog)
  end

  def site
    @site ||= sites(:madrid)
  end

  def test_valid
    assert root_level_term.valid?
    assert dependent_level_term.valid?
  end

  def test_creation_of_dependent_term
    new_term = root_level_term.terms.new(name_translations: { en: "Wolve", es: "Lobo" })
    assert new_term.valid?
    new_term.save
    assert_equal root_level_term.level + 1, new_term.level
    assert_equal vocabulary, new_term.vocabulary
    assert_equal 3, root_level_term.terms.count
    assert_equal root_level_term, new_term.parent_term
  end

  def test_creation_of_free_term
    new_term = vocabulary.terms.new(name_translations: { en: "Reptile", es: "Reptil" })
    assert new_term.valid?
    new_term.save
    assert_equal 0, new_term.level
    assert_equal vocabulary, new_term.vocabulary
    assert_nil new_term.parent_term
    assert_equal 0, new_term.terms.count
  end
end
<commit_msg>Add test to Term model for destroy with and without dependencies<commit_after># frozen_string_literal: true

require "test_helper"

class TermTest < ActiveSupport::TestCase
  def vocabulary
    @vocabulary ||= gobierto_common_vocabularies(:animals)
  end

  def root_level_term
    @root_level_term ||= gobierto_common_terms(:mammal)
  end

  def dependent_level_term
    @dependent_level_term ||= gobierto_common_terms(:dog)
  end

  def terms_with_dependencies
    @terms_with_dependencies ||= {
      issue:  gobierto_common_terms(:culture_term),
      scope:  gobierto_common_terms(:center_term),
      political_group: gobierto_common_terms(:marvel_term)
    }
  end

  def term_without_dependencies
    @term_without_dependencies ||= gobierto_common_terms(:cat)
  end

  def site
    @site ||= sites(:madrid)
  end

  def test_valid
    assert root_level_term.valid?
    assert dependent_level_term.valid?
  end

  def test_creation_of_dependent_term
    new_term = root_level_term.terms.new(name_translations: { en: "Wolve", es: "Lobo" })
    assert new_term.valid?
    new_term.save
    assert_equal root_level_term.level + 1, new_term.level
    assert_equal vocabulary, new_term.vocabulary
    assert_equal 3, root_level_term.terms.count
    assert_equal root_level_term, new_term.parent_term
  end

  def test_creation_of_free_term
    new_term = vocabulary.terms.new(name_translations: { en: "Reptile", es: "Reptil" })
    assert new_term.valid?
    new_term.save
    assert_equal 0, new_term.level
    assert_equal vocabulary, new_term.vocabulary
    assert_nil new_term.parent_term
    assert_equal 0, new_term.terms.count
  end

  def test_destroy_of_term_with_dependencies
    terms_with_dependencies.each do |_, term|
      refute term.destroy
    end
  end

  def test_destroy_of_term_without_dependencies
    assert term_without_dependencies.destroy
  end
end

{'fraction_non_alphanumeric': 0.07250079846694348, 'fraction_numerical': 0.0025550942190993293, 'mean_word_length': 4.363013698630137, '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': '3387205', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1045, 'n_words': 207}