reform
reform copied to clipboard
Skipped property is still passed for validation
Complete Description of Issue
I want to have an optional validation. I'm using skip_if
option when declaring property
on a form. In the validation
block I'm making it optional
inside params
so if the property is not passed to the validation, it would still validate successfully.
Steps to reproduce
Branch in my project: https://github.com/AndKiel/tournaments-api/tree/55eaf06f5e45e3969b0bc2720306d91e64aea6a3
Relevant files:
- https://github.com/AndKiel/tournaments-api/blob/55eaf06f5e45e3969b0bc2720306d91e64aea6a3/app/forms/tournament/update_form.rb
- https://github.com/AndKiel/tournaments-api/blob/55eaf06f5e45e3969b0bc2720306d91e64aea6a3/spec/forms/tournament/update_form_spec.rb
- https://github.com/AndKiel/tournaments-api/blob/55eaf06f5e45e3969b0bc2720306d91e64aea6a3/spec/forms/tournament/tournament_contract_spec.rb
Test run focused on the form spec and contract spec (it still has focus on the form spec from the other issue): https://github.com/AndKiel/tournaments-api/pull/29/checks?check_run_id=735646841
Expected behavior
I'm expecting skipped property not to be passed to the validation at all. When using Dry::Validation::Contract
and hash without a key is passed for the call
it works as expected and validation passes. In Reform
it's broken.
Actual behavior
Property key is still present and passed to validation with the value from validate()
invocation despite the fact that property
is declared with skip_if
option.
System configuration
Reform version: v2.3.1 (latest) dry-validation version: v1.5 (latest)