Skip to content

Commit

Permalink
Adding default message for uri? predicate (#477)
Browse files Browse the repository at this point in the history
* Adding default message for uri? predicate

* Rubocop fixes
  • Loading branch information
timjnh committed Mar 11, 2024
1 parent 7e93796 commit 529a2fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/errors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,7 @@ en:

uuid_v4?: "is not a valid UUID"

uri?: "is not a valid URI"

not:
empty?: "cannot be empty"
17 changes: 17 additions & 0 deletions spec/integration/params/predicates/uri_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

RSpec.describe "Predicates: uri?" do
subject(:schema) do
Dry::Schema.Params do
required(:uri) { str? & uri?(:https) }
end
end

it "passes with valid input" do
expect(schema.(uri: "https://www.example.com")).to be_success
end

it "fails with invalid input" do
expect(schema.(uri: "not-a-uri").errors.to_h).to eql(uri: ["is not a valid URI"])
end
end

0 comments on commit 529a2fb

Please sign in to comment.