simple-validators 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43f6166da95b3801727a71dab732e30e608032de
|
4
|
+
data.tar.gz: 38ba53ecc55e96c4a6d720edd7b2206959b8ea30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a92331afc9b90a57c21c6e0d13d1f935b216615cb87c736e77a6c81bb1bfe5f3b590ecc38132f60e6f6a70060ac3877e008b34b8f9fb6cbdf4e7510c11e73af7
|
7
|
+
data.tar.gz: 0d16a8c5f853c6ee6cb73595a3ac72dbd21b988ed60a0aef31f1107decae288bc67f679c4910c0afb8d8351eebf7551cb9262e35d13f2130764595c25c0d5359
|
data/lib/simple/validators.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Simple
|
2
|
+
module Validators
|
3
|
+
class SubdomainValidator < ActiveModel::EachValidator
|
4
|
+
def validate_each(record, attribute, value)
|
5
|
+
return if value.blank?
|
6
|
+
|
7
|
+
reserved_names = options.fetch(:reserved) { %w[www ftp mail pop smtp admin ssl sftp] }
|
8
|
+
if reserved_names.include?(value)
|
9
|
+
record.errors[attribute] << 'cannot be a reserved name'
|
10
|
+
end
|
11
|
+
|
12
|
+
record.errors[attribute] << 'must have between 1 and 63 letters' unless (1..63) === value.length
|
13
|
+
record.errors[attribute] << 'cannot start or end with a hyphen' unless value =~ /^[^-].*[^-]$/i
|
14
|
+
record.errors[attribute] << 'must be alphanumeric; A-Z, 0-9 or hyphen' unless value =~ /^[a-z0-9\-]*$/i
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Simple::Validators::SubdomainValidator do
|
4
|
+
let(:account) { Account.new }
|
5
|
+
|
6
|
+
context "valid subdomain" do
|
7
|
+
it "marks the record as valid" do
|
8
|
+
account.subdomain = "acme"
|
9
|
+
expect(account).to be_valid
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "invalid subdomain" do
|
14
|
+
it "when reserved marks the record as invalid" do
|
15
|
+
account.host = "www"
|
16
|
+
expect(account).not_to be_valid
|
17
|
+
end
|
18
|
+
|
19
|
+
it "when reserved marks the record as invalid" do
|
20
|
+
account.subdomain = "test"
|
21
|
+
expect(account).not_to be_valid
|
22
|
+
end
|
23
|
+
|
24
|
+
it "when too long marks the record as invalid" do
|
25
|
+
account.subdomain = "really-really-long-subdomain-that-exceeds-the-63-char-limit-keep-going-nearly-there"
|
26
|
+
expect(account).not_to be_valid
|
27
|
+
end
|
28
|
+
|
29
|
+
it "when starts with a hypen marks the record as invalid" do
|
30
|
+
account.subdomain = "-acme"
|
31
|
+
expect(account).not_to be_valid
|
32
|
+
end
|
33
|
+
|
34
|
+
it "when ends with a hypen marks the record as invalid" do
|
35
|
+
account.subdomain = "acme-"
|
36
|
+
expect(account).not_to be_valid
|
37
|
+
end
|
38
|
+
|
39
|
+
it "when it contains invalid chars the record as invalid" do
|
40
|
+
account.subdomain = "acme_test something"
|
41
|
+
expect(account).not_to be_valid
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Mytton
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- lib/simple/validators/email_validator.rb
|
50
|
+
- lib/simple/validators/subdomain_validator.rb
|
50
51
|
- lib/simple/validators/username_validator.rb
|
51
52
|
- lib/simple/validators/version.rb
|
52
53
|
- lib/simple/validators.rb
|
@@ -56,6 +57,7 @@ files:
|
|
56
57
|
- spec/dummy/app/assets/stylesheets/application.css
|
57
58
|
- spec/dummy/app/controllers/application_controller.rb
|
58
59
|
- spec/dummy/app/helpers/application_helper.rb
|
60
|
+
- spec/dummy/app/models/account.rb
|
59
61
|
- spec/dummy/app/models/user.rb
|
60
62
|
- spec/dummy/app/views/layouts/application.html.erb
|
61
63
|
- spec/dummy/config/application.rb
|
@@ -85,6 +87,7 @@ files:
|
|
85
87
|
- spec/dummy/script/rails
|
86
88
|
- spec/spec_helper.rb
|
87
89
|
- spec/validators/email_validator_spec.rb
|
90
|
+
- spec/validators/subdomain_validator_spec.rb
|
88
91
|
- spec/validators/username_validator_spec.rb
|
89
92
|
homepage: https://github.com/simpleweb/simple-validators
|
90
93
|
licenses: []
|
@@ -114,6 +117,7 @@ test_files:
|
|
114
117
|
- spec/dummy/app/assets/stylesheets/application.css
|
115
118
|
- spec/dummy/app/controllers/application_controller.rb
|
116
119
|
- spec/dummy/app/helpers/application_helper.rb
|
120
|
+
- spec/dummy/app/models/account.rb
|
117
121
|
- spec/dummy/app/models/user.rb
|
118
122
|
- spec/dummy/app/views/layouts/application.html.erb
|
119
123
|
- spec/dummy/config/application.rb
|
@@ -143,5 +147,6 @@ test_files:
|
|
143
147
|
- spec/dummy/script/rails
|
144
148
|
- spec/spec_helper.rb
|
145
149
|
- spec/validators/email_validator_spec.rb
|
150
|
+
- spec/validators/subdomain_validator_spec.rb
|
146
151
|
- spec/validators/username_validator_spec.rb
|
147
152
|
has_rdoc:
|