<commit_before>module RiotMongoMapper
  class HasValidationAssertion < Riot::AssertionMacro
    register :has_validation

    def evaluate(model, *validation_macro_info)
      validation_type, validation_name, options = validation_macro_info
      validation = model.send(:all_validations).detect do |valid|
        valid.key =~ %r{#{validation_type.to_s.camelize}} and valid.attribute == validation_name
      end
      options ||= {}
      case
      when validation_name.nil? || validation_type.nil?
        fail("validation name, type and potential options must be specified with this assertion macro")
      when validation.nil?
        fail("expected #{model} to have validation on #{validation_name} of type #{validation_type}")
      else
        options_valid = options.all? { |key,value| validation.send(key) == value }
        options_valid ? pass("#{model} has '#{validation_type}' validation '#{validation_name}' with options #{options.inspect}") :
                        fail("expected #{model} to have validations on #{validation_name} with options #{options.inspect} of type #{validation_type}")
      end
    end
  end
end<commit_msg>fix for mongo_mapper 0.9.0 now usign ActiveModel. completely stolen from<commit_after>module RiotMongoMapper
  class HasValidationAssertion < Riot::AssertionMacro
    register :has_validation

    def evaluate(model, *validation_macro_info)
      validation_type, validation_field, options = validation_macro_info
      type = validation_type.to_s

      %w{validates_ _of}.each { |part| type.gsub!(%r{#{part}},'') }

      validation = model._validators[validation_field].detect do |valid|
        valid.class.name =~ /#{type.camelize}/
      end

      options ||= {}

      case
        when validation_field.nil? || validation_type.nil?
          fail("validation field, type and potential options must be specified with this assertion macro")

        when validation.nil?
          fail("expected #{model} to have validation on #{validation_field} of type #{validation_type}")

        when (validation.class.name =~ %r{Length} and options[:within])
          range = options[:within].to_a
          if (validation.options[:minimum] == range.first) and (validation.options[:maximum] == range.last)
            pass("#{model} has '#{validation_type}' validation '#{validation_field}' with options #{options.inspect}")
          else
            fail("expected #{model} to have options #{options.inspect} on validation #{validation_type}")
          end

        else
          options_valid = options.all? { |key,value| validation.options[key] == value }
          if options_valid
            pass("#{model} has '#{validation_type}' validation '#{validation_field}' with options #{options.inspect}")
          else
            fail("expected #{model} to have options #{options.inspect} on validation #{validation_type}")
          end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11164383561643836, 'fraction_numerical': 0.0010273972602739725, 'mean_word_length': 3.276720351390922, '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': '5381591', 'n_tokens_mistral': 786, 'n_tokens_neox': 775, 'n_words': 214}