validates_as_hostname_label 1.1.1 → 1.1.2
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.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +41 -0
- data/Rakefile +2 -2
- data/lib/validates_as_hostname_label.rb +10 -8
- data/test/validates_as_hostname_label_test.rb +16 -15
- metadata +52 -33
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: a1c12b78dd8d83a1392c1442dbe02f9a917ebd40
|
|
4
|
+
data.tar.gz: b718bf9495cd78c293bddd406aee06eb7c52e849
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e195b3dc83ef7499c9eb8fc1565096ffe856ca46df784f0dc4842c1b4fa75e084000a2012009dc65305b3fb724b6f8d3bbe5b634d57ffe4e09e21d75e9fa4d06
|
|
7
|
+
data.tar.gz: 8fc1daeb566ad0b7b26ab63f4064ad7ffcc29af4434f9700aaedbc899f77ca378759572245de713ce2652331bd6550567430802c2cf5b45e8afd434a7dafb2b2
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
validates_as_hostname_label (1.1.1)
|
|
5
|
+
activerecord
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
activemodel (4.0.3)
|
|
11
|
+
activesupport (= 4.0.3)
|
|
12
|
+
builder (~> 3.1.0)
|
|
13
|
+
activerecord (4.0.3)
|
|
14
|
+
activemodel (= 4.0.3)
|
|
15
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
|
16
|
+
activesupport (= 4.0.3)
|
|
17
|
+
arel (~> 4.0.0)
|
|
18
|
+
activerecord-deprecated_finders (1.0.3)
|
|
19
|
+
activesupport (4.0.3)
|
|
20
|
+
i18n (~> 0.6, >= 0.6.4)
|
|
21
|
+
minitest (~> 4.2)
|
|
22
|
+
multi_json (~> 1.3)
|
|
23
|
+
thread_safe (~> 0.1)
|
|
24
|
+
tzinfo (~> 0.3.37)
|
|
25
|
+
arel (4.0.2)
|
|
26
|
+
atomic (1.1.15)
|
|
27
|
+
builder (3.1.4)
|
|
28
|
+
i18n (0.6.9)
|
|
29
|
+
minitest (4.7.5)
|
|
30
|
+
multi_json (1.9.0)
|
|
31
|
+
sqlite3 (1.3.9)
|
|
32
|
+
thread_safe (0.2.0)
|
|
33
|
+
atomic (>= 1.1.7, < 2)
|
|
34
|
+
tzinfo (0.3.38)
|
|
35
|
+
|
|
36
|
+
PLATFORMS
|
|
37
|
+
ruby
|
|
38
|
+
|
|
39
|
+
DEPENDENCIES
|
|
40
|
+
sqlite3
|
|
41
|
+
validates_as_hostname_label!
|
data/Rakefile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'rake'
|
|
2
2
|
require 'rake/testtask'
|
|
3
|
-
require '
|
|
3
|
+
require 'rdoc/task'
|
|
4
4
|
|
|
5
5
|
desc 'Default: run the validates_as_hostname_label tests'
|
|
6
6
|
task :default => :test
|
|
@@ -19,4 +19,4 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
|
19
19
|
rdoc.options << '--line-numbers' << '--inline-source'
|
|
20
20
|
rdoc.rdoc_files.include('README.*')
|
|
21
21
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
22
|
-
end
|
|
22
|
+
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
require 'active_record'
|
|
2
|
+
require 'active_support/core_ext/object/with_options'
|
|
3
|
+
|
|
1
4
|
# Adds ActiveRecord validation for hostname labels
|
|
2
5
|
module ValidatesAsHostnameLabel
|
|
3
|
-
|
|
4
6
|
# A hash of default options to use when calling <tt>validates_as_hostname_label</tt>.
|
|
5
7
|
#
|
|
6
8
|
# Defaults:
|
|
@@ -15,7 +17,7 @@ module ValidatesAsHostnameLabel
|
|
|
15
17
|
:reserved => %w(admin blog dev development ftp help imap mail pop pop3 sftp smtp staging stats status support www)
|
|
16
18
|
}
|
|
17
19
|
end
|
|
18
|
-
|
|
20
|
+
|
|
19
21
|
# Validates hostname labels by checking for:
|
|
20
22
|
#
|
|
21
23
|
# * Length between 1 and 63 characters long
|
|
@@ -27,7 +29,7 @@ module ValidatesAsHostnameLabel
|
|
|
27
29
|
#
|
|
28
30
|
# :allow_blank - Skip validation of the attribute is blank. Defaults to false.
|
|
29
31
|
# :allow_underscores - Allows underscores in hostname labels. Defaults to false.
|
|
30
|
-
# :reserved - Contains an array of reserved hostname labels to validate exclusion of.
|
|
32
|
+
# :reserved - Contains an array of reserved hostname labels to validate exclusion of.
|
|
31
33
|
# Defaults to ValidatesAsHostnameLabel.default_options[:reserved].
|
|
32
34
|
#
|
|
33
35
|
# I18n keys:
|
|
@@ -44,21 +46,21 @@ module ValidatesAsHostnameLabel
|
|
|
44
46
|
|
|
45
47
|
I18n.with_options :scope => 'validates_as_hostname_label' do |i18n|
|
|
46
48
|
validates_presence_of *attrs + [options] unless options.delete(:allow_blank) || options.delete(:allow_nil)
|
|
47
|
-
|
|
49
|
+
|
|
48
50
|
validates_exclusion_of *attrs + [{
|
|
49
51
|
:in => options.delete(:reserved),
|
|
50
52
|
:message => i18n.t('reserved', :default => 'is reserved'),
|
|
51
53
|
:allow_blank => true
|
|
52
54
|
}.merge(options)]
|
|
53
55
|
|
|
54
|
-
validates_format_of *attrs + [{
|
|
55
|
-
:with =>
|
|
56
|
+
validates_format_of *attrs + [{
|
|
57
|
+
:with => /\A[#{format}]*\z/i,
|
|
56
58
|
:message => i18n.t('invalid_format', :default => "may only contain #{characters.to_sentence} characters"),
|
|
57
59
|
:allow_blank => true
|
|
58
60
|
}.merge(options)]
|
|
59
61
|
|
|
60
62
|
validates_format_of *attrs + [{
|
|
61
|
-
:with =>
|
|
63
|
+
:with => /\A[^-_].*[^-_]\z/i,
|
|
62
64
|
:message => i18n.t('invalid_prefix_or_suffix', :default => 'may not start or end with a hyphen or underscore'),
|
|
63
65
|
:allow_blank => true
|
|
64
66
|
}.merge(options)]
|
|
@@ -72,4 +74,4 @@ module ValidatesAsHostnameLabel
|
|
|
72
74
|
end
|
|
73
75
|
end
|
|
74
76
|
|
|
75
|
-
ActiveRecord::Base.extend ValidatesAsHostnameLabel
|
|
77
|
+
ActiveRecord::Base.extend ValidatesAsHostnameLabel
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
|
-
require '
|
|
2
|
+
require 'sqlite3'
|
|
3
3
|
require 'test/unit'
|
|
4
4
|
require File.dirname(__FILE__) + '/../lib/validates_as_hostname_label'
|
|
5
5
|
|
|
6
|
+
I18n.enforce_available_locales = false
|
|
7
|
+
|
|
6
8
|
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
|
|
7
9
|
|
|
8
10
|
class Account < ActiveRecord::Base
|
|
@@ -43,11 +45,11 @@ class ValidatesAsHostnameLabelTest < Test::Unit::TestCase
|
|
|
43
45
|
def test_should_not_save_with_blank_subdomain_if_allow_option_is_not_specified
|
|
44
46
|
@account = Account.new :subdomain => nil
|
|
45
47
|
assert !@account.save
|
|
46
|
-
assert
|
|
48
|
+
assert !@account.errors[:subdomain].empty?
|
|
47
49
|
|
|
48
50
|
@account.subdomain = ''
|
|
49
51
|
assert !@account.save
|
|
50
|
-
assert
|
|
52
|
+
assert !@account.errors[:subdomain].empty?
|
|
51
53
|
end
|
|
52
54
|
|
|
53
55
|
def test_should_save_with_blank_subdomain
|
|
@@ -63,35 +65,35 @@ class ValidatesAsHostnameLabelTest < Test::Unit::TestCase
|
|
|
63
65
|
def test_should_not_save_with_too_long_of_a_subdomain
|
|
64
66
|
@account = Account.new :subdomain => ('t' * 64)
|
|
65
67
|
assert !@account.save
|
|
66
|
-
assert
|
|
68
|
+
assert !@account.errors[:subdomain].empty?
|
|
67
69
|
end
|
|
68
70
|
|
|
69
71
|
def test_should_not_save_with_invalid_characters
|
|
70
72
|
@account = Account.new :subdomain => '!@#$%^&*'
|
|
71
73
|
assert !@account.save
|
|
72
|
-
assert
|
|
74
|
+
assert !@account.errors[:subdomain].empty?
|
|
73
75
|
end
|
|
74
76
|
|
|
75
77
|
def test_should_not_save_with_subdomains_beginning_with_a_hyphen_or_underscore
|
|
76
78
|
@account = Account.new :subdomain => '-testing'
|
|
77
79
|
@account.subdomain_with_underscores = '_testing'
|
|
78
80
|
assert !@account.save
|
|
79
|
-
assert
|
|
80
|
-
assert
|
|
81
|
+
assert !@account.errors[:subdomain].empty?
|
|
82
|
+
assert !@account.errors[:subdomain_with_underscores].empty?
|
|
81
83
|
end
|
|
82
84
|
|
|
83
85
|
def test_should_not_save_with_subdomains_ending_with_a_hyphen_or_underscore
|
|
84
86
|
@account = Account.new :subdomain => 'testing-'
|
|
85
87
|
@account.subdomain_with_underscores = 'testing_'
|
|
86
88
|
assert !@account.save
|
|
87
|
-
assert
|
|
88
|
-
assert
|
|
89
|
+
assert !@account.errors[:subdomain].empty?
|
|
90
|
+
assert !@account.errors[:subdomain_with_underscores].empty?
|
|
89
91
|
end
|
|
90
92
|
|
|
91
93
|
def test_should_not_save_subdomains_with_an_underscore_if_allow_underscores_option_is_false
|
|
92
94
|
@account = Account.new :subdomain => 'test_ing'
|
|
93
95
|
assert !@account.save
|
|
94
|
-
assert
|
|
96
|
+
assert !@account.errors[:subdomain].empty?
|
|
95
97
|
end
|
|
96
98
|
|
|
97
99
|
def test_should_save_subdomains_with_an_underscore_if_allow_underscores_option_is_true
|
|
@@ -103,20 +105,19 @@ class ValidatesAsHostnameLabelTest < Test::Unit::TestCase
|
|
|
103
105
|
ValidatesAsHostnameLabel::default_options[:reserved].each do |hostname|
|
|
104
106
|
@account = Account.new :subdomain => hostname
|
|
105
107
|
assert !@account.save
|
|
106
|
-
assert
|
|
108
|
+
assert !@account.errors[:subdomain].empty?
|
|
107
109
|
end
|
|
108
110
|
end
|
|
109
111
|
|
|
110
112
|
def test_should_not_save_with_a_reserved_subdomain_from_a_list
|
|
111
113
|
@account = Account.new :subdomain_with_reserved => 'funky'
|
|
112
114
|
assert !@account.save
|
|
113
|
-
assert
|
|
115
|
+
assert !@account.errors[:subdomain_with_reserved].empty?
|
|
114
116
|
end
|
|
115
117
|
|
|
116
118
|
def test_should_not_be_valid_with_a_subdomain_not_from_the_list
|
|
117
119
|
@account = Account.new :subdomain_with_reserved => 'qqqfds'
|
|
118
120
|
assert !@account.save
|
|
119
|
-
assert
|
|
121
|
+
assert @account.errors[:subdomain_with_reserved].empty?
|
|
120
122
|
end
|
|
121
|
-
|
|
122
|
-
end
|
|
123
|
+
end
|
metadata
CHANGED
|
@@ -1,60 +1,79 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: validates_as_hostname_label
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.1.2
|
|
5
5
|
platform: ruby
|
|
6
|
-
authors:
|
|
6
|
+
authors:
|
|
7
7
|
- Sean Huber
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
date: 2014-03-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activerecord
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: sqlite3
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
16
41
|
description: Checks for valid hostname labels
|
|
17
42
|
email: shuber@huberry.com
|
|
18
43
|
executables: []
|
|
19
|
-
|
|
20
44
|
extensions: []
|
|
21
|
-
|
|
22
45
|
extra_rdoc_files: []
|
|
23
|
-
|
|
24
|
-
files:
|
|
46
|
+
files:
|
|
25
47
|
- init.rb
|
|
26
48
|
- lib/validates_as_hostname_label.rb
|
|
49
|
+
- Gemfile
|
|
50
|
+
- Gemfile.lock
|
|
27
51
|
- MIT-LICENSE
|
|
28
52
|
- Rakefile
|
|
29
53
|
- README.rdoc
|
|
30
54
|
- test/validates_as_hostname_label_test.rb
|
|
31
|
-
has_rdoc: true
|
|
32
55
|
homepage: http://github.com/shuber/validates_as_hostname_label
|
|
33
56
|
licenses: []
|
|
34
|
-
|
|
57
|
+
metadata: {}
|
|
35
58
|
post_install_message:
|
|
36
59
|
rdoc_options: []
|
|
37
|
-
|
|
38
|
-
require_paths:
|
|
60
|
+
require_paths:
|
|
39
61
|
- lib
|
|
40
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
|
-
requirements:
|
|
42
|
-
- -
|
|
43
|
-
- !ruby/object:Gem::Version
|
|
44
|
-
version:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
version: "0"
|
|
51
|
-
version:
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - '>='
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '0'
|
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - '>='
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '0'
|
|
52
72
|
requirements: []
|
|
53
|
-
|
|
54
73
|
rubyforge_project:
|
|
55
|
-
rubygems_version:
|
|
74
|
+
rubygems_version: 2.0.14
|
|
56
75
|
signing_key:
|
|
57
|
-
specification_version:
|
|
76
|
+
specification_version: 4
|
|
58
77
|
summary: Checks for valid hostname labels
|
|
59
|
-
test_files:
|
|
78
|
+
test_files:
|
|
60
79
|
- test/validates_as_hostname_label_test.rb
|