From 385a43a568e32fa265871b2c1102b5aa11cb36b5 Mon Sep 17 00:00:00 2001 From: Spyros Kazanas Date: Thu, 11 Jan 2024 00:27:18 +0200 Subject: [PATCH 1/2] Add error message for uuid_v1? uuid_v2? uuid_v3? and uuid_v5? --- config/errors.yml | 10 +++++++++- .../params/predicates/uuid_v1_spec.rb | 17 +++++++++++++++++ .../params/predicates/uuid_v2_spec .rb | 17 +++++++++++++++++ .../params/predicates/uuid_v3_spec.rb | 17 +++++++++++++++++ .../params/predicates/uuid_v5_spec.rb | 17 +++++++++++++++++ 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 spec/integration/params/predicates/uuid_v1_spec.rb create mode 100644 spec/integration/params/predicates/uuid_v2_spec .rb create mode 100644 spec/integration/params/predicates/uuid_v3_spec.rb create mode 100644 spec/integration/params/predicates/uuid_v5_spec.rb diff --git a/config/errors.yml b/config/errors.yml index 95afc96f..92825418 100644 --- a/config/errors.yml +++ b/config/errors.yml @@ -105,9 +105,17 @@ en: default: "must be %{size} bytes long" range: "must be within %{size_left} - %{size_right} bytes long" + uri?: "is not a valid URI" + + uuid_v1?: "is not a valid UUID" + + uuid_v2?: "is not a valid UUID" + + uuid_v3?: "is not a valid UUID" + uuid_v4?: "is not a valid UUID" - uri?: "is not a valid URI" + uuid_v5?: "is not a valid UUID" not: empty?: "cannot be empty" diff --git a/spec/integration/params/predicates/uuid_v1_spec.rb b/spec/integration/params/predicates/uuid_v1_spec.rb new file mode 100644 index 00000000..f0bfce2e --- /dev/null +++ b/spec/integration/params/predicates/uuid_v1_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +RSpec.describe "Predicates: uuid_v1?" do + subject(:schema) do + Dry::Schema.Params do + required(:uuid).value(:string, :uuid_v1?) + end + end + + it "passes with valid input" do + expect(schema.(uuid: '2e14d58e-afff-11ee-a506-0242ac120002')).to be_success + end + + it "fails with invalid input" do + expect(schema.(uuid: "not-uuid").errors.to_h).to eql(uuid: ["is not a valid UUID"]) + end +end diff --git a/spec/integration/params/predicates/uuid_v2_spec .rb b/spec/integration/params/predicates/uuid_v2_spec .rb new file mode 100644 index 00000000..a4263fe5 --- /dev/null +++ b/spec/integration/params/predicates/uuid_v2_spec .rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +RSpec.describe "Predicates: uuid_v2?" do + subject(:schema) do + Dry::Schema.Params do + required(:uuid).value(:string, :uuid_v2?) + end + end + + it "passes with valid input" do + expect(schema.(uuid: '000003e8-afff-21ee-a300-325096b39f47')).to be_success + end + + it "fails with invalid input" do + expect(schema.(uuid: "not-uuid").errors.to_h).to eql(uuid: ["is not a valid UUID"]) + end +end diff --git a/spec/integration/params/predicates/uuid_v3_spec.rb b/spec/integration/params/predicates/uuid_v3_spec.rb new file mode 100644 index 00000000..d7066616 --- /dev/null +++ b/spec/integration/params/predicates/uuid_v3_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +RSpec.describe "Predicates: uuid_v3?" do + subject(:schema) do + Dry::Schema.Params do + required(:uuid).value(:string, :uuid_v3?) + end + end + + it "passes with valid input" do + expect(schema.(uuid: '1d955abe-9522-33d5-a788-a1b186b163dc')).to be_success + end + + it "fails with invalid input" do + expect(schema.(uuid: "not-uuid").errors.to_h).to eql(uuid: ["is not a valid UUID"]) + end +end diff --git a/spec/integration/params/predicates/uuid_v5_spec.rb b/spec/integration/params/predicates/uuid_v5_spec.rb new file mode 100644 index 00000000..7afc244e --- /dev/null +++ b/spec/integration/params/predicates/uuid_v5_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +RSpec.describe "Predicates: uuid_v5?" do + subject(:schema) do + Dry::Schema.Params do + required(:uuid).value(:string, :uuid_v5?) + end + end + + it "passes with valid input" do + expect(schema.(uuid: '601d90d0-8611-502d-b49b-86c0779b6159')).to be_success + end + + it "fails with invalid input" do + expect(schema.(uuid: "not-uuid").errors.to_h).to eql(uuid: ["is not a valid UUID"]) + end +end From 482403c55b0d015f33d94a8334b5bdcf11bab886 Mon Sep 17 00:00:00 2001 From: Spyros Kazanas Date: Thu, 18 Jan 2024 00:22:18 +0200 Subject: [PATCH 2/2] Fix Rubocop offences --- spec/integration/params/predicates/uuid_v1_spec.rb | 2 +- .../params/predicates/{uuid_v2_spec .rb => uuid_v2_spec.rb} | 2 +- spec/integration/params/predicates/uuid_v3_spec.rb | 2 +- spec/integration/params/predicates/uuid_v5_spec.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename spec/integration/params/predicates/{uuid_v2_spec .rb => uuid_v2_spec.rb} (85%) diff --git a/spec/integration/params/predicates/uuid_v1_spec.rb b/spec/integration/params/predicates/uuid_v1_spec.rb index f0bfce2e..2e184fc0 100644 --- a/spec/integration/params/predicates/uuid_v1_spec.rb +++ b/spec/integration/params/predicates/uuid_v1_spec.rb @@ -8,7 +8,7 @@ end it "passes with valid input" do - expect(schema.(uuid: '2e14d58e-afff-11ee-a506-0242ac120002')).to be_success + expect(schema.(uuid: "2e14d58e-afff-11ee-a506-0242ac120002")).to be_success end it "fails with invalid input" do diff --git a/spec/integration/params/predicates/uuid_v2_spec .rb b/spec/integration/params/predicates/uuid_v2_spec.rb similarity index 85% rename from spec/integration/params/predicates/uuid_v2_spec .rb rename to spec/integration/params/predicates/uuid_v2_spec.rb index a4263fe5..65fc8e26 100644 --- a/spec/integration/params/predicates/uuid_v2_spec .rb +++ b/spec/integration/params/predicates/uuid_v2_spec.rb @@ -8,7 +8,7 @@ end it "passes with valid input" do - expect(schema.(uuid: '000003e8-afff-21ee-a300-325096b39f47')).to be_success + expect(schema.(uuid: "000003e8-afff-21ee-a300-325096b39f47")).to be_success end it "fails with invalid input" do diff --git a/spec/integration/params/predicates/uuid_v3_spec.rb b/spec/integration/params/predicates/uuid_v3_spec.rb index d7066616..be295b0e 100644 --- a/spec/integration/params/predicates/uuid_v3_spec.rb +++ b/spec/integration/params/predicates/uuid_v3_spec.rb @@ -8,7 +8,7 @@ end it "passes with valid input" do - expect(schema.(uuid: '1d955abe-9522-33d5-a788-a1b186b163dc')).to be_success + expect(schema.(uuid: "1d955abe-9522-33d5-a788-a1b186b163dc")).to be_success end it "fails with invalid input" do diff --git a/spec/integration/params/predicates/uuid_v5_spec.rb b/spec/integration/params/predicates/uuid_v5_spec.rb index 7afc244e..53ce6ecd 100644 --- a/spec/integration/params/predicates/uuid_v5_spec.rb +++ b/spec/integration/params/predicates/uuid_v5_spec.rb @@ -8,7 +8,7 @@ end it "passes with valid input" do - expect(schema.(uuid: '601d90d0-8611-502d-b49b-86c0779b6159')).to be_success + expect(schema.(uuid: "601d90d0-8611-502d-b49b-86c0779b6159")).to be_success end it "fails with invalid input" do