validators 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,38 +0,0 @@
1
- module ActiveModel
2
- module Validations
3
- class SubdomainValidator < EachValidator
4
- # Rules taken from http://www.zytrax.com/books/dns/apa/names.html
5
- def validate_each(record, attribute, value)
6
- return if value.blank? && options[:allow_blank]
7
- return if value.nil? && options[:allow_nil]
8
- return if valid_label?(value.to_s)
9
-
10
- record.errors.add(attribute, :invalid_subdomain,
11
- message: options[:message],
12
- value: value
13
- )
14
- end
15
-
16
- def valid_label?(label)
17
- !label.start_with?("-") &&
18
- !label.match(/\A\d+\z/) &&
19
- label.match(/\A[a-z0-9-]{1,63}\z/i)
20
- end
21
- end
22
-
23
- module ClassMethods
24
- # Validates whether or not the specified URL is valid.
25
- #
26
- # class User < ActiveRecord::Base
27
- # validates_subdomain_format_of :subdomain
28
- # validates_subdomain :subdomain
29
- # end
30
- #
31
- def validates_subdomain_format_of(*attr_names)
32
- validates_with SubdomainValidator, _merge_attributes(attr_names)
33
- end
34
-
35
- alias_method :validates_subdomain, :validates_subdomain_format_of
36
- end
37
- end
38
- end
@@ -1,18 +0,0 @@
1
- VALID_SUBDOMAINS = %W[
2
- #{'a'*63}
3
- mysite
4
- my-site
5
- mysite-
6
- mysite1234
7
- 1234mysite
8
- MYSITE
9
- MYSITE1234
10
- 1234MYSITE
11
- mysite--
12
- ]
13
-
14
- INVALID_SUBDOMAINS = %W[
15
- -mysite
16
- 1234
17
- #{'a'*64}
18
- ]
@@ -1,17 +0,0 @@
1
- require "test_helper"
2
-
3
- class ValidatesSubdomainTest < Minitest::Test
4
- VALID_SUBDOMAINS.each do |subdomain|
5
- test "accepts #{subdomain}" do
6
- site = Site.new(subdomain)
7
- assert site.valid?
8
- end
9
- end
10
-
11
- INVALID_SUBDOMAINS.each do |subdomain|
12
- test "rejects #{subdomain}" do
13
- site = Site.new(subdomain)
14
- refute site.valid?
15
- end
16
- end
17
- end