Skip to content

Commit

Permalink
Add spec reproducing issue with custom type and hash validation
Browse files Browse the repository at this point in the history
  • Loading branch information
edgenard committed Jan 28, 2022
1 parent d65ba02 commit 1f5ca65
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/integration/schema/macros/hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@
end
end

context 'with custom coercible type' do

subject(:schema) do
ExpirationDate = Types::DateTime.constructor { |value| value.to_time.round.to_datetime }
Dry::Schema.Params do
required(:unnested_dated).value(ExpirationDate)
required(:foo).hash do
required(:bar).hash do
required(:nested_date).value(ExpirationDate)
end
end
end
end

let(:input) { {foo: {nested_date: '2021-11-11T00:00:00+00:00'}, unnested_date: '2021-11-11T00:00:00+00:00' } }

specify do
expect(result).to be_successful
expect(result.to_h).to eql(foo: {date: DateTime.new(2021, 11, 11) }, unnested_data: DateTime.new(2021, 11, 11))
end
end

context "constrained type" do
let(:hash_schema) do
Types::Hash.schema({}).constrained([:filled])
Expand Down

0 comments on commit 1f5ca65

Please sign in to comment.