-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make KeyValidator faster by sorting keys and using binary search algo…
…rithm (Array#bsearch) - attempt #2
- Loading branch information
1 parent
e143710
commit 8ad1c89
Showing
2 changed files
with
36 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Dry::Schema, "key searching algorithm" do | ||
it "works properly with keys that are prefixes of other keys" do | ||
schema = Dry::Schema.define do | ||
config.validate_keys = true | ||
|
||
required(:a).filled(:string) | ||
required(:fooA).filled(:string) | ||
required(:foo).array(:hash) do | ||
required(:bar).filled(:string) | ||
end | ||
end | ||
|
||
expect(schema.(a: "string", fooA: "string", foo: "string").errors.to_h) | ||
.to eql({foo: ["must be an array"]}) | ||
end | ||
end |