<commit_before># encoding: utf-8
Module.send :include, Module.new {
  def test(name, &block)
    define_method("test_#{name.gsub(/[^a-z0-9]/i, "_")}".to_sym, &block)
  end
  alias :should :test
}

module FriendlyId
  module Test

    # Tests for any model that implements FriendlyId. Any test that tests model
    # features should include this module.
    module Generic

      def setup
        klass.send delete_all_method
      end

      def teardown
        klass.send delete_all_method
      end

      def instance
        raise NotImplementedError
      end

      def klass
        raise NotImplementedError
      end

      def other_class
        raise NotImplementedError
      end

      def find_method
        raise NotImplementedError
      end

      def create_method
        raise NotImplementedError
      end

      def update_method
        raise NotImplementedError
      end

      def validation_exceptions
        return RuntimeError
      end

      def assert_validation_error
        if validation_exceptions
          assert_raise(*[validation_exceptions].flatten) do
            yield
          end
        else  # DataMapper does not raise Validation Errors
          i = yield
          if i.kind_of?(TrueClass) || i.kind_of?(FalseClass)
            assert !i
          else
            instance = i
            assert_not_empty instance.errors
          end
        end
      end

      test "models should have a friendly id config" do
        assert_not_nil klass.friendly_id_config
      end

      test "instances should have a friendly id by default" do
        assert_not_nil instance.friendly_id
      end

      test "instances should have a friendly id status" do
        assert_not_nil instance.friendly_id_status
      end

      test "instances should be findable by their friendly id" do
        assert_equal instance, klass.send(find_method, instance.friendly_id)
      end

      test "instances should be findable by their numeric id as an integer" do
        assert_equal instance, klass.send(find_method, instance.id.to_i)
      end

      test "instances should be findable by their numeric id as a string" do
        assert_equal instance, klass.send(find_method, instance.id.to_s)
      end

      test "instances should be findable by a numeric friendly_id" do
        instance = klass.send(create_method, :name => "206")
        assert_equal instance, klass.send(find_method, instance.friendly_id)
      end

      test "creation should raise an error if the friendly_id text is reserved" do<commit_msg>Small test fix for Sequel.<commit_after># encoding: utf-8
Module.send :include, Module.new {
  def test(name, &block)
    define_method("test_#{name.gsub(/[^a-z0-9]/i, "_")}".to_sym, &block)
  end
  alias :should :test
}

module FriendlyId
  module Test

    # Tests for any model that implements FriendlyId. Any test that tests model
    # features should include this module.
    module Generic

      def setup
        klass.send delete_all_method
      end

      def teardown
        klass.send delete_all_method
      end

      def instance
        raise NotImplementedError
      end

      def klass
        raise NotImplementedError
      end

      def other_class
        raise NotImplementedError
      end

      def find_method
        raise NotImplementedError
      end

      def create_method
        raise NotImplementedError
      end

      def update_method
        raise NotImplementedError
      end

      def validation_exceptions
        return RuntimeError
      end

      def assert_validation_error
        if validation_exceptions
          assert_raise(*[validation_exceptions].flatten) do
            yield
          end
        else  # DataMapper does not raise Validation Errors
          i = yield
          if i.kind_of?(TrueClass) || i.kind_of?(FalseClass)
            assert !i
          else
            instance = i
            assert_not_empty instance.errors
          end
        end
      end

      test "models should have a friendly id config" do
        assert_not_nil klass.friendly_id_config
      end

      test "instances should have a friendly id by default" do
        assert_not_nil instance.friendly_id
      end

      test "instances should have a friendly id status" do
        assert_not_nil instance.friendly_id_status
      end

      test "instances should be findable by their friendly id" do
        assert_equal instance, klass.send(find_method, instance.friendly_id)
      end

      test "instances should be findable by their numeric id as an integer" do
        assert_equal instance, klass.send(find_method, instance.id.to_i)
      end

      test "instances should be findable by their numeric id as a string" do
        assert_equal instance, klass.send(find_method, instance.id.to_s)
      end

      test "instances should be findable by a numeric friendly_id" do
        instance = klass.send(create_method, :name => "206")
        assert_equal instance, klass.send(find_method, "206")
      end

      test "creation should raise an error if the friendly_id text is reserved" do
{'fraction_non_alphanumeric': 0.0484375, 'fraction_numerical': 0.0029296875, 'mean_word_length': 2.202626641651032, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1323247', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1376, 'n_words': 471}