dry-validation: :form input_processor no longer coerces strings to int when using Rails params?
This code used to work (in version 0.9.x) but now fails in 0.10.2:
describe "type coersion (from rails params)" do
let (:params) { ActionController::Parameters.new({ age: '18' }) }
let (:validated) { schema.call(params) }
let (:schema) do
Dry::Validation.Schema do
configure do
config.input_processor = :form
config.hash_type = :symbolized
end
required(:age).filled(:int?)
end
end
it "coerces to integer" do
expect(validated.output[:age]).to eq 18
end
it "is valid" do
expect(validated.success?).to eq true
end
end
Plain hashes still work, though:
describe "type coersion (from hash)" do
let (:params) { { age: '18' } }
let (:validated) { schema.call(params) }
let (:schema) do
Dry::Validation.Schema do
configure do
config.input_processor = :form
config.hash_type = :symbolized
end
required(:age).filled(:int?)
end
end
it "coerces to integer" do
expect(validated.output[:age]).to eq 18
end
it "is valid" do
expect(validated.success?).to eq true
end
end
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 29 (17 by maintainers)
This works too:
I just ran into the same issue while using v0.11.1
Dry::Validation.Formis not coercing stringified integers when passing in an instance ofActionController::Parametersparams.permit!did not work for me..to_unsafe_hashdid the trick.As mentioned in https://github.com/dry-rb/dry-validation/issues/262#issuecomment-251148890 dedicated support for rails is out of the scope of this gem. If someone wants to provide it as
dry-validation-rails, I suggest approaching us on the forum once 1.0 is out/close to release. Thanks.