Skip to content

Instantly share code, notes, and snippets.

@tombruijn
Last active February 10, 2016 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tombruijn/c24c594b12d2a97f7f7b to your computer and use it in GitHub Desktop.
Save tombruijn/c24c594b12d2a97f7f7b to your computer and use it in GitHub Desktop.
dry-validation/master test
source "https://rubygems.org"
gem "dry-validation", git: "git@github.com:dryrb/dry-validation.git"
require "dry-validation"
class Schema < Dry::Validation::Schema
key(:password, &:filled?)
key(:password_confirmation, &:filled?)
rule(:password_confirmation) do
value(:password).eql?(value(:password_confirmation))
end
end
class SchemaWithNameChange < Dry::Validation::Schema
key(:password, &:filled?)
key(:password_confirmation, &:filled?)
rule(:password_confirmation_foo) do
value(:password).eql?(value(:password_confirmation))
end
end
p Schema.new.call(password: "test", password_confirmation: "test").messages
# => {}
p Schema.new.call(password: "test", password_confirmation: "foo").messages
# => {:password_confirmation=>["password_confirmation must be equal to foo", "password_confirmation must be filled"]}
p SchemaWithNameChange.new.call(password: "test", password_confirmation: "foo").messages
# => {:password_confirmation_foo=>["password_confirmation_foo must be equal to foo"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment