Created
June 28, 2018 17:48
-
-
Save fpinzn/949575857746b75dd1766b9a69e58286 to your computer and use it in GitHub Desktop.
dry-validation nested config inside rules not working
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
InnerSchema = Dry::Validation.Schema do | |
configure do | |
option :letter_array | |
end | |
required(:letter).filled(:str?) | |
validate(letter_in_array: :letter) do |letter| | |
letter_array.include?(letter) | |
end | |
end | |
RSpec::describe 'InnerSchema' do | |
it('should pass with a know letter') do | |
expect(InnerSchema.with(letter_array: ['a']) | |
.call( { :letter => 'a' } ).success?).to be true | |
end | |
end | |
OuterSchema = Dry::Validation.Schema do | |
required(:container) { hash? } | |
rule(is_inside_letter_known: [:container]) do |container| | |
container.schema(InnerSchema.with(letter_array: ['b'])) | |
end | |
end | |
RSpec::describe 'OuterSchema' do | |
it('should pass with a nested know letter') do | |
expect(OuterSchema.call( { :container => { :letter => 'b' } }).success?) | |
.to be true | |
end | |
end |
davidpelaez
commented
Jun 28, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment