dry-rb / dry-schema

Coercion and validation for data structures
https://dry-rb.org/gems/dry-schema
MIT License
425 stars 110 forks source link

Forward #translate method to underlying backend #398

Closed krekoten closed 2 years ago

krekoten commented 2 years ago

Description

Discovered this when received [[]] as input in our API. Schema in our API defined in same way as in specs in this PR. There is issue related to this PR from another guy in dry-validation repo dry-rb/dry-validation#692

How to reproduce

without fix

bundle exec rspec spec/integration/messages/namespaced_spec.rb:69
Run options: include {:locations=>{"./spec/integration/messages/namespaced_spec.rb"=>[69]}}

Randomized with seed 21602
F

Failures:

  1) Namespaced messages with OR messages uses namespaced messages
     Failure/Error: t["#{config.top_namespace}.#{key}", locale: locale]

     NameError:
       undefined local variable or method `t' for #<Dry::Schema::Messages::Namespaced:0x00007fb357a88fb0>
     # ./lib/dry/schema/messages/abstract.rb:72:in `translate'
     # ./lib/dry/schema/message_compiler.rb:126:in `block in or_translator'
     # ./lib/dry/schema/message/or/single_path.rb:41:in `dump'
     # ./lib/dry/schema/message/or/single_path.rb:53:in `to_h'
     # ./lib/dry/schema/message_set.rb:108:in `map'
     # ./lib/dry/schema/message_set.rb:108:in `messages_map'
     # ./lib/dry/schema/extensions/hints/message_set_methods.rb:37:in `to_h'
     # ./lib/dry/schema/message_set.rb:72:in `[]'
     # ./spec/integration/messages/namespaced_spec.rb:72:in `block (3 levels) in <top (required)>'

with fix

Specs pass

solnic commented 2 years ago

Thanks!