<commit_before>require "test_helper"
require "reform/form/dry"
require "reform/form/coercion"

class DryValidationDefaultGroupTest < Minitest::Spec
  Session = Struct.new(:username, :email, :password, :confirm_password, :starts_at, :active, :color)

  class SessionForm < TestForm
    include Reform::Form::Dry
    include Coercion

    property :username
    property :email
    property :password
    property :confirm_password
    property :starts_at, type: Types::Form::DateTime
    property :active, type: Types::Form::Bool
    property :color

    validation do
      required(:username).filled
      required(:email).filled
      required(:starts_at).filled(:date_time?)
      required(:active).filled(:bool?)<commit_msg>Add a test for separate schema i.e. no validation block<commit_after>require "test_helper"
require "reform/form/dry"
require "reform/form/coercion"

class DryValidationNoBlockTest < Minitest::Spec
  Session = Struct.new(:name, :email)
  SessionSchema = Dry::Validation.Schema do
    required(:name).filled
    required(:email).filled
  end

  class SessionForm < TestForm
    include Coercion

    property :name
    property :email

    validation schema: SessionSchema
  end

  let (:form) { SessionForm.new(Session.new) }

  # valid.
  it do
    form.validate(name: "Helloween", email: "yep").must_equal true
    form.errors.messages.inspect.must_equal "{}"
  end

  it "invalid" do
    form.validate(name: "", email: "yep").must_equal false
    form.errors.messages.inspect.must_equal "{:name=>[\"must be filled\"]}"
  end
end

class DryValidationDefaultGroupTest < Minitest::Spec
  Session = Struct.new(:username, :email, :password, :confirm_password, :starts_at, :active, :color)

  class SessionForm < TestForm
    include Reform::Form::Dry
    include Coercion

    property :username
    property :email
    property :password
    property :confirm_password
    property :starts_at, type: Types::Form::DateTime
    property :active, type: Types::Form::Bool
    property :color

    validation do
      required(:username).filled
      required(:email).filled
      required(:starts_at).filled(:date_time?)
      required(:active).filled(:bool?)
{'fraction_non_alphanumeric': 0.11462631820265932, 'fraction_numerical': 0.0, 'mean_word_length': 4.14622641509434, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 4, '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': '1871086', 'n_tokens_mistral': 655, 'n_tokens_neox': 636, 'n_words': 155}