<commit_before>require 'test_helper'

class ConfigurationItemTest < ActiveSupport::TestCase
  should "be valid" do
    assert ! ConfigurationItem.new.valid?
    assert ConfigurationItem.new(:item => Factory(:server)).valid?
  end

  context "#identifier" do
    should "not raise if there's no item (other validations will fail in this case)" do
      ci = ConfigurationItem.new
      assert ! ci.valid?
    end

    should "generate the identifier before validations" do
      ci = ConfigurationItem.new(:item => Factory(:server))
      assert ci.valid?
      assert_not_nil ci.identifier
      assert ci.save
    end
  end
end
<commit_msg>Ensure every concrete CI object defines a #to_s public instance method<commit_after>require 'test_helper'

class ConfigurationItemTest < ActiveSupport::TestCase
  should "be valid" do
    assert ! ConfigurationItem.new.valid?
    assert ConfigurationItem.new(:item => Factory(:server)).valid?
  end

  context "#identifier" do
    should "not raise if there's no item (other validations will fail in this case)" do
      ci = ConfigurationItem.new
      assert ! ci.valid?
    end

    should "generate the identifier before validations" do
      ci = ConfigurationItem.new(:item => Factory(:server))
      assert ci.valid?
      assert_not_nil ci.identifier
      assert ci.save
    end

    should "have a #to_s method in each real-CI-object classes" do
      ActiveRecord::Base.subclasses.each do |klass|
        if klass.instance_methods.include?(:configuration_item)
          assert klass.instance_method_already_implemented?(:to_s), "#{klass}#to_s is not defined (required for playing with ConfigurationItem)"
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.08244994110718493, 'fraction_numerical': 0.0, 'mean_word_length': 3.4244791666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1770041', 'n_tokens_mistral': 463, 'n_tokens_neox': 458, 'n_words': 153}