Skip to content

Commit

Permalink
Fix tests for blank?
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Feb 6, 2025
1 parent a8d51db commit 99ddf60
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions spec/graphql/schema/validator/length_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

# This string doesn't respond to blank:
non_blank_string = ValidatorHelpers::NonBlankString.new("")
refute non_blank_string.respond_to?(:blank?), "NonBlankString doesn't have a blank? method"
result = schema.execute("query($str: String!) { validated(value: $str) }", variables: { str: non_blank_string })
assert_nil result["data"].fetch("validated")
assert_equal ["value is too short (minimum is 5)"], result["errors"].map { |e| e["message"] }
Expand Down
9 changes: 7 additions & 2 deletions spec/graphql/schema/validator/validator_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ def blank?
end

class NonBlankString < String
if method_defined?(:blank?)
undef :blank?
def initialize
# Gems loaded during test execution can define this method on String
# eg Rails, Rubocop
if respond_to?(:blank?)
s.class.undef_method(:blank?)
end
super
end
end

Expand Down

0 comments on commit 99ddf60

Please sign in to comment.