missing_validators 0.4.0 → 0.4.1
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.
data/README.md
CHANGED
@@ -67,6 +67,12 @@ Or any ruby class:
|
|
67
67
|
validates :blog, url: true
|
68
68
|
end
|
69
69
|
|
70
|
+
You can specify domains to which the URL domain should belong in one of the folowing ways:
|
71
|
+
|
72
|
+
validates :url, url: { domains: 'com' }
|
73
|
+
validates :url, url: { domains: :com }
|
74
|
+
validates :url, url: { domains: [:com, 'edu'] }
|
75
|
+
|
70
76
|
RSpec matcher is also available for your convenience:
|
71
77
|
|
72
78
|
describe User do
|
@@ -16,7 +16,7 @@ class EmailValidator < ActiveModel::EachValidator
|
|
16
16
|
return if allow_blank && value.blank?
|
17
17
|
|
18
18
|
domains = Array.wrap(options[:domain])
|
19
|
-
email = value && value.downcase
|
19
|
+
email = value && value.downcase || ''
|
20
20
|
in_valid_domain = domains.empty? ? true : domains.any? { |domain| email.end_with?(".#{domain.downcase}") }
|
21
21
|
|
22
22
|
has_valid_format = !!(value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i)
|
@@ -25,20 +25,23 @@ describe EmailValidator do
|
|
25
25
|
let(:klass) do
|
26
26
|
Class.new do
|
27
27
|
include ActiveModel::Validations
|
28
|
-
attr_accessor :email
|
28
|
+
attr_accessor :email, :name
|
29
29
|
validates :email, email: { domain: "edu" }
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
it { should allow_value("user@example.edu").for(:email) }
|
34
34
|
it { should_not allow_value("user@example.com").for(:email) }
|
35
|
+
|
36
|
+
it { should ensure_valid_email_format_of(:email) }
|
37
|
+
it { should_not ensure_valid_email_format_of(:name) }
|
35
38
|
end
|
36
39
|
|
37
40
|
context "email set as an array of strings and symbols" do
|
38
41
|
let(:klass) do
|
39
42
|
Class.new do
|
40
43
|
include ActiveModel::Validations
|
41
|
-
attr_accessor :email
|
44
|
+
attr_accessor :email, :name
|
42
45
|
validates :email, email: { domain: ['com', :edu, 'Com.Au'] }
|
43
46
|
end
|
44
47
|
end
|
@@ -48,6 +51,9 @@ describe EmailValidator do
|
|
48
51
|
it { should allow_value("user@example.com.au").for(:email) }
|
49
52
|
it { should allow_value("user@example.Com.Au").for(:email) }
|
50
53
|
it { should_not allow_value("user@example.org").for(:email) }
|
54
|
+
|
55
|
+
it { should ensure_valid_email_format_of(:email) }
|
56
|
+
it { should_not ensure_valid_email_format_of(:name) }
|
51
57
|
end
|
52
58
|
end
|
53
59
|
end
|
@@ -35,38 +35,44 @@ describe UrlValidator do
|
|
35
35
|
it { should_not allow_value("http://user_example.a").for(:url) }
|
36
36
|
end
|
37
37
|
|
38
|
-
context "url is in the
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
context "url is in the specific domain" do
|
39
|
+
context "url specified as symbol" do
|
40
|
+
let(:klass) do
|
41
|
+
Class.new do
|
42
|
+
include ActiveModel::Validations
|
43
|
+
attr_accessor :url, :name
|
44
|
+
validates :url, url: { domain: :org }
|
45
|
+
end
|
44
46
|
end
|
45
|
-
end
|
46
47
|
|
47
|
-
|
48
|
+
subject { klass.new }
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
it { should_not allow_value("http://example.com").for(:url) }
|
52
|
-
end
|
50
|
+
it { should ensure_valid_url_format_of(:url) }
|
51
|
+
it { should_not ensure_valid_url_format_of(:name) }
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
Class.new do
|
57
|
-
include ActiveModel::Validations
|
58
|
-
attr_accessor :url, :name
|
59
|
-
validates :url, url: { domain: [:org, 'edu', 'Com.Au'] }
|
60
|
-
end
|
53
|
+
it { should allow_value("http://example.org").for(:url) }
|
54
|
+
it { should_not allow_value("http://example.com").for(:url) }
|
61
55
|
end
|
62
56
|
|
63
|
-
|
57
|
+
context "url specified as array of strings and symbols" do
|
58
|
+
let(:klass) do
|
59
|
+
Class.new do
|
60
|
+
include ActiveModel::Validations
|
61
|
+
attr_accessor :url, :name
|
62
|
+
validates :url, url: { domain: [:org, 'edu', 'Com.Au'] }
|
63
|
+
end
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
subject { klass.new }
|
67
|
+
|
68
|
+
it { should ensure_valid_url_format_of(:url) }
|
69
|
+
it { should_not ensure_valid_url_format_of(:name) }
|
70
|
+
|
71
|
+
it { should allow_value("http://example.org").for(:url) }
|
72
|
+
it { should allow_value("http://example.edu").for(:url) }
|
73
|
+
it { should allow_value("http://example.com.au").for(:url) }
|
74
|
+
it { should allow_value("http://example.Com.Au").for(:url) }
|
75
|
+
it { should_not allow_value("http://example.com").for(:url) }
|
76
|
+
end
|
71
77
|
end
|
72
78
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: missing_validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2013-09-09 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70201404629460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70201404629460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: shoulda-matchers
|
27
|
-
requirement: &
|
27
|
+
requirement: &70201404627380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70201404627380
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activemodel
|
38
|
-
requirement: &
|
38
|
+
requirement: &70201404625320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 3.0.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70201404625320
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activesupport
|
49
|
-
requirement: &
|
49
|
+
requirement: &70201404624480 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 3.0.0
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70201404624480
|
58
58
|
description: Adds some handy validators.
|
59
59
|
email:
|
60
60
|
- andrew.gridnev@gmail.com
|