<commit_before>module HasDigest
  module Shoulda
    # Asserts that <tt>has_digest :name</tt> has been called with the given
    # options, and that the necessary database columns are present.
    def should_have_digest(name, options = {})
      options.assert_valid_keys(:depends)

      context "#{model_class.name} with has_digest :#{name}" do
        should_have_db_column name, :type => :string, :limit => 40

        should "generate digest for :#{name}" do
          assert_not_nil model_class.has_digest_attributes[name]
        end

        if options[:depends]
          dependencies = options[:depends]
          dependencies = [dependencies] unless dependencies.respond_to?(:each)
          dependencies.unshift(:salt) if model_class.column_names.include?('salt')

          should "generate digest for :#{name} from #{dependencies.to_sentence}" do
            attributes = model_class.has_digest_attributes[name] || {}
            assert_equal dependencies, attributes[:dependencies]
          end
        end
      end
    end
  end
end

Test::Unit::TestCase.extend(HasDigest::Shoulda)<commit_msg>should_have_digest can take a :limit option specifying db column size.<commit_after>module HasDigest
  module Shoulda
    # Asserts that <tt>has_digest :name</tt> has been called with the given
    # options, and that the necessary database columns are present. +options+
    # may contain two keys:
    # * +depends+: either a single attribute name or an array of attribtues
    #   names. (Specifying <tt>:salt</tt> here is unnecessary.)
    # * +limit+: if your db column for the given digest doesn't have
    #   <tt>:limit => 40</tt>, you may specify its size here.
    def should_have_digest(name, options = {})
      options.assert_valid_keys(:depends, :limit)

      context "#{model_class.name} with has_digest :#{name}" do
        should_have_db_column name, :type => :string, :limit => (options[:limit] || 40)

        should "generate digest for :#{name}" do
          assert_not_nil model_class.has_digest_attributes[name]
        end

        if options[:depends]
          dependencies = options[:depends]
          dependencies = [dependencies] unless dependencies.respond_to?(:each)
          dependencies.unshift(:salt) if model_class.column_names.include?('salt')

          should "generate digest for :#{name} from #{dependencies.to_sentence}" do
            attributes = model_class.has_digest_attributes[name] || {}
            assert_equal dependencies, attributes[:dependencies]
          end
        end
      end
    end
  end
end

Test::Unit::TestCase.extend(HasDigest::Shoulda)
{'fraction_non_alphanumeric': 0.10087886893389378, 'fraction_numerical': 0.0022927015666794038, 'mean_word_length': 3.1687898089171975, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, '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': '4484900', 'n_tokens_mistral': 749, 'n_tokens_neox': 715, 'n_words': 209}