From 1f5ca6516bb8268e9900631e2ba8cb23cb92c45a Mon Sep 17 00:00:00 2001 From: Emmanuel Genard Date: Thu, 27 Jan 2022 20:54:27 -0500 Subject: [PATCH 1/6] Add spec reproducing issue with custom type and hash validation --- spec/integration/schema/macros/hash_spec.rb | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/integration/schema/macros/hash_spec.rb b/spec/integration/schema/macros/hash_spec.rb index 83504c9bb..036a96c5e 100644 --- a/spec/integration/schema/macros/hash_spec.rb +++ b/spec/integration/schema/macros/hash_spec.rb @@ -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]) From 08e156dc6df26ad1adaa50a75aab2300ec096b5d Mon Sep 17 00:00:00 2001 From: Emmanuel Genard Date: Fri, 28 Jan 2022 09:41:56 -0500 Subject: [PATCH 2/6] Fix typos in test --- spec/integration/schema/macros/hash_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/integration/schema/macros/hash_spec.rb b/spec/integration/schema/macros/hash_spec.rb index 036a96c5e..e3d73f54a 100644 --- a/spec/integration/schema/macros/hash_spec.rb +++ b/spec/integration/schema/macros/hash_spec.rb @@ -103,7 +103,7 @@ subject(:schema) do ExpirationDate = Types::DateTime.constructor { |value| value.to_time.round.to_datetime } Dry::Schema.Params do - required(:unnested_dated).value(ExpirationDate) + required(:unnested_date).value(ExpirationDate) required(:foo).hash do required(:bar).hash do required(:nested_date).value(ExpirationDate) @@ -112,7 +112,13 @@ end end - let(:input) { {foo: {nested_date: '2021-11-11T00:00:00+00:00'}, unnested_date: '2021-11-11T00:00:00+00:00' } } + let(:input) do + { + foo: { bar: {nested_date: '2021-11-11T00:00:00+00:00'}}, + unnested_date: '2021-11-11T00:00:00+00:00', + } + + end specify do expect(result).to be_successful From 15f3e16cd68e955c3bf613f8e3557a6af55e1f60 Mon Sep 17 00:00:00 2001 From: Emmanuel Genard Date: Fri, 28 Jan 2022 09:43:05 -0500 Subject: [PATCH 3/6] rubocop autocorrect linting errors --- spec/integration/schema/macros/hash_spec.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/spec/integration/schema/macros/hash_spec.rb b/spec/integration/schema/macros/hash_spec.rb index e3d73f54a..1bcfb067b 100644 --- a/spec/integration/schema/macros/hash_spec.rb +++ b/spec/integration/schema/macros/hash_spec.rb @@ -98,8 +98,7 @@ end end - context 'with custom coercible type' do - + context "with custom coercible type" do subject(:schema) do ExpirationDate = Types::DateTime.constructor { |value| value.to_time.round.to_datetime } Dry::Schema.Params do @@ -114,15 +113,14 @@ let(:input) do { - foo: { bar: {nested_date: '2021-11-11T00:00:00+00:00'}}, - unnested_date: '2021-11-11T00:00:00+00:00', + foo: {bar: {nested_date: "2021-11-11T00:00:00+00:00"}}, + unnested_date: "2021-11-11T00:00:00+00:00" } - end 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)) + expect(result.to_h).to eql(foo: {date: DateTime.new(2021, 11, 11)}, unnested_data: DateTime.new(2021, 11, 11)) end end From 2012ca4f51ffbbe3b72781e9e65a4121500f7aec Mon Sep 17 00:00:00 2001 From: Emmanuel Genard Date: Fri, 28 Jan 2022 09:45:21 -0500 Subject: [PATCH 4/6] Mark spec as pending --- spec/integration/schema/macros/hash_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/integration/schema/macros/hash_spec.rb b/spec/integration/schema/macros/hash_spec.rb index 1bcfb067b..d3b334aac 100644 --- a/spec/integration/schema/macros/hash_spec.rb +++ b/spec/integration/schema/macros/hash_spec.rb @@ -119,6 +119,7 @@ end specify do + pending 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 From 004f9cff3731c2dd8d0630e22903d00c5104492b Mon Sep 17 00:00:00 2001 From: Emmanuel Genard Date: Fri, 28 Jan 2022 19:16:46 -0500 Subject: [PATCH 5/6] fix typos in spec --- spec/integration/schema/macros/hash_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/integration/schema/macros/hash_spec.rb b/spec/integration/schema/macros/hash_spec.rb index d3b334aac..16e0b8936 100644 --- a/spec/integration/schema/macros/hash_spec.rb +++ b/spec/integration/schema/macros/hash_spec.rb @@ -121,7 +121,7 @@ specify do pending 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)) + expect(result.to_h).to eql(foo: {bar: {nested_date: DateTime.new(2021, 11, 11)}}, unnested_date: DateTime.new(2021, 11, 11)) end end From be89d3035bd9a5b2f22dcfc5edfab8a9e39bbd01 Mon Sep 17 00:00:00 2001 From: Emmanuel Genard Date: Fri, 28 Jan 2022 19:18:46 -0500 Subject: [PATCH 6/6] make spec completely pending --- spec/integration/schema/macros/hash_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/integration/schema/macros/hash_spec.rb b/spec/integration/schema/macros/hash_spec.rb index 16e0b8936..10728e665 100644 --- a/spec/integration/schema/macros/hash_spec.rb +++ b/spec/integration/schema/macros/hash_spec.rb @@ -118,7 +118,7 @@ } end - specify do + xspecify do pending expect(result).to be_successful expect(result.to_h).to eql(foo: {bar: {nested_date: DateTime.new(2021, 11, 11)}}, unnested_date: DateTime.new(2021, 11, 11))