remove unused nilable_uri rule (default uri rule is now nilable)
also use length rule instead of regex
This commit is contained in:
parent
b6a134db6a
commit
4c9eac4699
7 changed files with 17 additions and 94 deletions
|
|
@ -1,5 +1,6 @@
|
|||
require "validation"
|
||||
require "validation/rule/regular_expression"
|
||||
require "validation/rule/length"
|
||||
require "validation/rule/not_empty"
|
||||
require "validation/rule/uri"
|
||||
|
||||
|
|
@ -18,7 +19,6 @@ require "diaspora_federation/validators/rules/birthday"
|
|||
require "diaspora_federation/validators/rules/boolean"
|
||||
require "diaspora_federation/validators/rules/diaspora_id"
|
||||
require "diaspora_federation/validators/rules/guid"
|
||||
require "diaspora_federation/validators/rules/nilable_uri"
|
||||
require "diaspora_federation/validators/rules/not_nil"
|
||||
require "diaspora_federation/validators/rules/public_key"
|
||||
require "diaspora_federation/validators/rules/tag_count"
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ module DiasporaFederation
|
|||
rule :last_name, regular_expression: {regex: /\A[^;]{,32}\z/}
|
||||
|
||||
# this urls can be relative
|
||||
rule :photo_large_url, [:not_nil, nilableURI: [:path]]
|
||||
rule :photo_medium_url, [:not_nil, nilableURI: [:path]]
|
||||
rule :photo_small_url, [:not_nil, nilableURI: [:path]]
|
||||
rule :photo_large_url, [:not_nil, URI: [:path]]
|
||||
rule :photo_medium_url, [:not_nil, URI: [:path]]
|
||||
rule :photo_small_url, [:not_nil, URI: [:path]]
|
||||
|
||||
# rule :exported_key, :public_key
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ module DiasporaFederation
|
|||
|
||||
rule :diaspora_id, %i(not_empty diaspora_id)
|
||||
|
||||
rule :url, %i(not_nil nilableURI)
|
||||
rule :url, %i(not_nil URI)
|
||||
|
||||
rule :profile, :not_nil
|
||||
|
||||
|
|
|
|||
|
|
@ -12,16 +12,15 @@ module DiasporaFederation
|
|||
rule :last_name, regular_expression: {regex: /\A[^;]{,32}\z/}
|
||||
|
||||
# this urls can be relative
|
||||
rule :image_url, nilableURI: [:path]
|
||||
rule :image_url_medium, nilableURI: [:path]
|
||||
rule :image_url_small, nilableURI: [:path]
|
||||
rule :image_url, URI: [:path]
|
||||
rule :image_url_medium, URI: [:path]
|
||||
rule :image_url_small, URI: [:path]
|
||||
|
||||
rule :birthday, :birthday
|
||||
|
||||
# TODO: replace regex with "length: {maximum: xxx}" but this rule doesn't allow nil now.
|
||||
rule :gender, regular_expression: {regex: /\A.{,255}\z/}
|
||||
rule :bio, regular_expression: {regex: /\A.{,65535}\z/}
|
||||
rule :location, regular_expression: {regex: /\A.{,255}\z/}
|
||||
rule :gender, length: {maximum: 255}
|
||||
rule :bio, length: {maximum: 65_535}
|
||||
rule :location, length: {maximum: 255}
|
||||
|
||||
rule :searchable, :boolean
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
module Validation
|
||||
module Rule
|
||||
# URI validation rule
|
||||
|
||||
# It allows +nil+, so maybe add an additional {Rule::NotNil} rule.
|
||||
class NilableURI < Validation::Rule::URI
|
||||
# The error key for this rule
|
||||
# @return [Symbol] error key
|
||||
def error_key
|
||||
:nilableURI
|
||||
end
|
||||
|
||||
# Determines if value is a valid URI
|
||||
def valid_value?(uri_string)
|
||||
uri_string.nil? || super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -9,12 +9,12 @@ module DiasporaFederation
|
|||
|
||||
rule :acct_uri, :not_empty
|
||||
|
||||
rule :alias_url, [:not_nil, nilableURI: %i(host path)]
|
||||
rule :hcard_url, [:not_nil, nilableURI: %i(host path)]
|
||||
rule :seed_url, %i(not_nil nilableURI)
|
||||
rule :profile_url, [:not_nil, nilableURI: %i(host path)]
|
||||
rule :atom_url, [:not_nil, nilableURI: %i(host path)]
|
||||
rule :salmon_url, [:not_nil, nilableURI: %i(host path)]
|
||||
rule :alias_url, [:not_nil, URI: %i(host path)]
|
||||
rule :hcard_url, [:not_nil, URI: %i(host path)]
|
||||
rule :seed_url, %i(not_nil URI)
|
||||
rule :profile_url, [:not_nil, URI: %i(host path)]
|
||||
rule :atom_url, [:not_nil, URI: %i(host path)]
|
||||
rule :salmon_url, [:not_nil, URI: %i(host path)]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
describe Validation::Rule::NilableURI do
|
||||
it "has an error key" do
|
||||
expect(described_class.new.error_key).to eq(:nilableURI)
|
||||
end
|
||||
|
||||
context "validation" do
|
||||
it "validates a valid uri" do
|
||||
validator = Validation::Validator.new(OpenStruct.new(uri: "http://example.com"))
|
||||
validator.rule(:uri, :nilableURI)
|
||||
|
||||
expect(validator).to be_valid
|
||||
expect(validator.errors).to be_empty
|
||||
end
|
||||
|
||||
it "validates nil" do
|
||||
validator = Validation::Validator.new(OpenStruct.new(uri: nil))
|
||||
validator.rule(:uri, :nilableURI)
|
||||
|
||||
expect(validator).to be_valid
|
||||
expect(validator.errors).to be_empty
|
||||
end
|
||||
|
||||
it "fails when given an invalid uri" do
|
||||
validator = Validation::Validator.new(OpenStruct.new(uri: "foo:/%urim"))
|
||||
validator.rule(:uri, :nilableURI)
|
||||
|
||||
expect(validator).not_to be_valid
|
||||
expect(validator.errors).to include(:uri)
|
||||
end
|
||||
|
||||
context "part validation" do
|
||||
it "fails to validate when given a uri without a host" do
|
||||
validator = Validation::Validator.new(OpenStruct.new(uri: "http:foo@"))
|
||||
validator.rule(:uri, :nilableURI)
|
||||
|
||||
expect(validator).not_to be_valid
|
||||
expect(validator.errors).to include(:uri)
|
||||
end
|
||||
|
||||
it "fails to validate when given a uri without a scheme" do
|
||||
validator = Validation::Validator.new(OpenStruct.new(uri: "example.com"))
|
||||
validator.rule(:uri, :nilableURI)
|
||||
|
||||
expect(validator).not_to be_valid
|
||||
expect(validator.errors).to include(:uri)
|
||||
end
|
||||
|
||||
it "fails to validate when given a uri without a path" do
|
||||
validator = Validation::Validator.new(OpenStruct.new(uri: "http://example.com"))
|
||||
validator.rule(:uri, nilableURI: %i(host path))
|
||||
|
||||
expect(validator).not_to be_valid
|
||||
expect(validator.errors).to include(:uri)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue