-
-
Save tombruijn/c24c594b12d2a97f7f7b to your computer and use it in GitHub Desktop.
dry-validation/master test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "dry-validation", git: "git@github.com:dryrb/dry-validation.git" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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