a guid is at most 255 chars long.

This commit is contained in:
Benjamin Neff 2016-07-09 19:30:05 +02:00
parent 0980294a0d
commit f7d269cd6a
2 changed files with 10 additions and 2 deletions

View file

@ -2,7 +2,7 @@ module Validation
module Rule
# GUID validation rule
#
# Valid is a +String+ that is at least 16 chars long and contains only:
# Valid is a +String+ that is at least 16 and at most 255 chars long. It contains only:
# * Letters: a-z
# * Numbers: 0-9
# * Special chars: '-', '_', '@', '.' and ':'
@ -30,7 +30,7 @@ module Validation
# Determines if value is a valid +GUID+
def valid_value?(value)
params[:nilable] && value.nil? || value.is_a?(String) && value.downcase =~ /\A[0-9a-z\-_@.:]{16,}\z/
params[:nilable] && value.nil? || value.is_a?(String) && value.downcase =~ /\A[0-9a-z\-_@.:]{16,255}\z/
end
end
end

View file

@ -61,6 +61,14 @@ describe Validation::Rule::Guid do
expect(validator.errors).to include(:guid)
end
it "fails if the string is too long" do
validator = Validation::Validator.new(OpenStruct.new(guid: "a" * 256))
validator.rule(:guid, :guid)
expect(validator).not_to be_valid
expect(validator.errors).to include(:guid)
end
it "fails if the string contains invalid chars" do
validator = Validation::Validator.new(OpenStruct.new(guid: "ghijklmnopqrstuvwxyz++"))
validator.rule(:guid, :guid)