a guid is at most 255 chars long.
This commit is contained in:
parent
0980294a0d
commit
f7d269cd6a
2 changed files with 10 additions and 2 deletions
|
|
@ -2,7 +2,7 @@ module Validation
|
||||||
module Rule
|
module Rule
|
||||||
# GUID validation 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
|
# * Letters: a-z
|
||||||
# * Numbers: 0-9
|
# * Numbers: 0-9
|
||||||
# * Special chars: '-', '_', '@', '.' and ':'
|
# * Special chars: '-', '_', '@', '.' and ':'
|
||||||
|
|
@ -30,7 +30,7 @@ module Validation
|
||||||
|
|
||||||
# Determines if value is a valid +GUID+
|
# Determines if value is a valid +GUID+
|
||||||
def valid_value?(value)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,14 @@ describe Validation::Rule::Guid do
|
||||||
expect(validator.errors).to include(:guid)
|
expect(validator.errors).to include(:guid)
|
||||||
end
|
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
|
it "fails if the string contains invalid chars" do
|
||||||
validator = Validation::Validator.new(OpenStruct.new(guid: "ghijklmnopqrstuvwxyz++"))
|
validator = Validation::Validator.new(OpenStruct.new(guid: "ghijklmnopqrstuvwxyz++"))
|
||||||
validator.rule(:guid, :guid)
|
validator.rule(:guid, :guid)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue