Skip to content

Commit

Permalink
adds check that it is not schema error for rule_error? method
Browse files Browse the repository at this point in the history
  • Loading branch information
moofkit committed Oct 8, 2020
1 parent 04b511b commit 63449fd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dry/validation/evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def rule_error?(path = nil)
if path.nil?
!key(self.path).empty?
else
result.error?(path)
result.rule_error?(path)
end
end

Expand Down
7 changes: 7 additions & 0 deletions lib/dry/validation/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ def schema_error?(key)
schema_result.error?(key)
end

# Check if the rules includes an error for the provided key
#
# @api private
def rule_error?(key)
!schema_error?(key) && error?(key)
end

# Check if there's any error for the provided key
#
# This does not consider errors from the nested values
Expand Down
6 changes: 6 additions & 0 deletions spec/integration/contract/evaluator/errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
{name: ["expected"], email: ["also expected"]}
)
end

it "does not evaluate if schema with provided key is falling down" do
expect(contract.new.(name: nil, email: "some@email.com").errors.to_h).to eql(
{name: ["must be a string"]}
)
end
end
end
end

0 comments on commit 63449fd

Please sign in to comment.