You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I'm getting an error in the following combination
gem 'dry-validation', '~> 1.4
Affects my production application: YES.
Ruby version: '2.5.7'
OS: Mac OS
class ValidateParams < Dry::Validation::Contract
schema do
required(:data).hash do
required(:relationships).hash do
required(:object).hash do
required(:data).hash do
required(:id).filled(:string)
end
end
end
end
end
register_macro(:format) do |macro:|
if value&.!~ macro.args.first
message = 'nvalid format'
key(keys.flatten).failure(message)
end
end
rule(%i[data relationships object data id]).validate(format: /some reg exp/)
end
scenario:
I'm trying to check that the type of the nested hash is Hash,
for this purpose, in specs, I assign to it an Array, so I expect to get a message:
{data: {relationships: {object: {data: ['must be a hash']}}}}
RSpec.describe ValidateParams do
let(:validation) { described_class.new }
context 'invalid type of inested hash' do
before do
params[:data][:relationships][:object][:data] = []
end
it 'looks like failure' do
message = {data: {relationships: {object: {data: ['must be a hash']}}}}
expect(validation.call(params).errors.to_h).to eq(message)
end
end
instead of that, I get the following error:
Failure/Error: if value&.!~ macro.args.first
TypeError:
no implicit conversion of Symbol into Integer
Please note that the error started to occur only after adding the rule which checks for the format of a key included in the nested hash.
if I change the checking type to sting or integer I get another error:
before do
params[:data][:relationships][:object][:data] = 'some string'
end
Failure/Error: if value&.!~ macro.args.first
TypeError:
String does not have #dig method
Also, it might be important that the point where the error happens is the method 'value'
The text was updated successfully, but these errors were encountered:
Hello,
I'm getting an error in the following combination
scenario:
I'm trying to check that the type of the nested hash is Hash,
for this purpose, in specs, I assign to it an Array, so I expect to get a message:
{data: {relationships: {object: {data: ['must be a hash']}}}}
instead of that, I get the following error:
Please note that the error started to occur only after adding the rule which checks for the format of a key included in the nested hash.
if I change the checking type to sting or integer I get another error:
Also, it might be important that the point where the error happens is the method 'value'
The text was updated successfully, but these errors were encountered: