email_validator 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +31 -31
- data/lib/email_validator.rb +2 -2
- data/spec/email_validator_spec.rb +217 -204
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bd676f012ed7b109082842ed227bc1881aec6ac24f0e1ed4be24772b206b14f
|
4
|
+
data.tar.gz: 6c2f92e0a494f751b690743b15d4d97fd8dd1f9213b8cb2640d6f8f729fca51f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dd2ab72b087727acec6c7509d3ffa2a51e35074b99113bc8b105c16fc62e9c3288712516e3fc0f15be125d83e0d7db50d368da269672d7ecdddec9ba21f925e
|
7
|
+
data.tar.gz: e35ab67f7e7337b1bb1cd04d27d0f47dee128b093cdd6015fdade7967b404441d7abc522dcec18bfda8e682e7ae5418a24ba3a400afa9292b6585e796b644c27
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,10 @@ This file is used to list changes made in `email_validator`.
|
|
5
5
|
All notable changes to this project will be documented in this file.
|
6
6
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
7
7
|
|
8
|
+
## 2.2.0 (2020-12-09)
|
9
|
+
|
10
|
+
* [karlwilbur] - Rename `:strict` -> `:rfc`; `:moderate` -> `:strict`
|
11
|
+
|
8
12
|
## 2.1.0 (2020-12-09)
|
9
13
|
|
10
14
|
* [karlwilbur] - Add linters and commit hooks to validate code prior to commits
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# EmailValidator
|
2
2
|
|
3
|
-
[![Build Status](https://
|
4
|
-
[![Code Climate](https://codeclimate.com/github/
|
5
|
-
[![Test Coverage](https://codeclimate.com/github/
|
3
|
+
[![Build Status](https://travis-ci.com/K-and-R/email_validator.svg?branch=master)](http://travis-ci.com/K-and-R/email_validator)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/K-and-R/email_validator/badges/gpa.svg)](https://codeclimate.com/github/K-and-R/email_validator)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/K-and-R/email_validator/badges/coverage.svg)](https://codeclimate.com/github/K-and-R/email_validator/coverage)
|
6
6
|
|
7
7
|
An email validator for Rails 3+.
|
8
8
|
|
9
|
-
Supports RFC-2822-compliant and RFC-5321-compliant email validation.
|
9
|
+
Supports RFC-2822-compliant and RFC-5321-compliant email validation using RFC-3696 validation.
|
10
10
|
|
11
11
|
Formerly found at: <https://github.com/balexand/email_validator>
|
12
12
|
|
@@ -17,11 +17,11 @@ is extremely loose. It just checks that there's an `@` with something before and
|
|
17
17
|
after it without any whitespace. See [this article by David Gilbertson](https://hackernoon.com/the-100-correct-way-to-validate-email-addresses-7c4818f24643)
|
18
18
|
for an explanation of why.
|
19
19
|
|
20
|
-
We understand that
|
21
|
-
supported by using the `:
|
20
|
+
We understand that many use cases require an increased level of validation. This
|
21
|
+
is supported by using the `:strict` validation mode. Additionally, the `:rfc`
|
22
22
|
RFC-compliant mode will consider technically valid emails address as valid which
|
23
23
|
may not be wanted, such as the valid `user` or `user@somehost` addresses. These
|
24
|
-
would be valid in `:
|
24
|
+
would be valid in `:rfc` mode but not valid in `:loose` or `:strict`.
|
25
25
|
|
26
26
|
## Installation
|
27
27
|
|
@@ -48,10 +48,10 @@ validates :my_email_attribute, email: true
|
|
48
48
|
You may wish to allow domains without a FDQN, like `user@somehost`. While this
|
49
49
|
is technically a valid address, it is uncommon to consider such address valid.
|
50
50
|
We will consider them valid by default with the `:loose` checking. Disallowed
|
51
|
-
by setting `require_fqdn: true` or by enabling `:
|
51
|
+
by setting `require_fqdn: true` or by enabling `:strict` checking:
|
52
52
|
|
53
53
|
```ruby
|
54
|
-
validates :my_email_attribute, email: {mode: :
|
54
|
+
validates :my_email_attribute, email: {mode: :strict, require_fqdn: true}
|
55
55
|
```
|
56
56
|
|
57
57
|
You can also limit to a single domain (e.g: this might help if, for example, you
|
@@ -86,67 +86,67 @@ end
|
|
86
86
|
This it the default validation mode of this gem. It is intentionally extremely
|
87
87
|
loose (see the [Validation Philosophy section](#validation_philosophy) above. It
|
88
88
|
just checks that there's an `@` with something before and after it without any
|
89
|
-
whitespace.
|
89
|
+
whitespace.
|
90
90
|
|
91
|
-
###
|
91
|
+
### Strict mode
|
92
92
|
|
93
|
-
Enabling `:
|
94
|
-
be expected in most common everyday usage.
|
93
|
+
Enabling `:strict` checking will check for a "normal" email format that would
|
94
|
+
be expected in most common everyday usage. Strict mode basically checks for a
|
95
95
|
properly sized and formatted mailbox label, a single "@" symbol, and a properly
|
96
|
-
sized and formatted FQDN. Enabling `:
|
96
|
+
sized and formatted FQDN. Enabling `:strict` mode will also enable `:require_fqdn`
|
97
97
|
configuration option.
|
98
98
|
|
99
|
-
|
99
|
+
Strict mode can be enabled globally by requiring `email_validator/strict` in
|
100
100
|
your `Gemfile`, by setting the option in `config/initializers/email_validator.rb`,
|
101
101
|
or by specifying the option in a specific `validates` call.
|
102
102
|
|
103
103
|
* `Gemfile`:
|
104
104
|
|
105
105
|
```ruby
|
106
|
-
gem 'email_validator',
|
106
|
+
gem 'email_validator', require: 'email_validator/strict'
|
107
107
|
```
|
108
108
|
|
109
109
|
* `config/initializers/email_validator.rb`:
|
110
110
|
|
111
111
|
```ruby
|
112
112
|
if defined?(EmailValidator)
|
113
|
-
EmailValidator.default_options[:mode] = :
|
113
|
+
EmailValidator.default_options[:mode] = :strict
|
114
114
|
end
|
115
115
|
```
|
116
116
|
|
117
117
|
* `validates` call:
|
118
118
|
|
119
119
|
```ruby
|
120
|
-
validates :my_email_attribute, email: {mode: :
|
120
|
+
validates :my_email_attribute, email: {mode: :strict}
|
121
121
|
```
|
122
122
|
|
123
|
-
###
|
123
|
+
### RFC mode
|
124
124
|
|
125
|
-
In order to have
|
126
|
-
enable `:
|
125
|
+
In order to have RFC-compliant validation (according to [http://www.remote.org/jochen/mail/info/chars.html](https://web.archive.org/web/20150508102948/http://www.remote.org/jochen/mail/info/chars.html)),
|
126
|
+
enable `:rfc` mode.
|
127
127
|
|
128
|
-
You can do this globally by requiring `email_validator/
|
128
|
+
You can do this globally by requiring `email_validator/rfc` in your `Gemfile`,
|
129
129
|
by setting the options in `config/initializers/email_validator.rb`, or you can do
|
130
130
|
this in a specific `validates` call.
|
131
131
|
|
132
132
|
* `Gemfile`:
|
133
133
|
|
134
134
|
```ruby
|
135
|
-
gem 'email_validator',
|
135
|
+
gem 'email_validator', require: 'email_validator/rfc'
|
136
136
|
```
|
137
137
|
|
138
138
|
* `config/initializers/email_validator.rb`:
|
139
139
|
|
140
140
|
```ruby
|
141
141
|
if defined?(EmailValidator)
|
142
|
-
EmailValidator.default_options[:mode] = :
|
142
|
+
EmailValidator.default_options[:mode] = :rfc
|
143
143
|
end
|
144
144
|
```
|
145
145
|
|
146
146
|
* `validates` call:
|
147
147
|
|
148
148
|
```ruby
|
149
|
-
validates :my_email_attribute, email: {mode: :
|
149
|
+
validates :my_email_attribute, email: {mode: :rfc}
|
150
150
|
```
|
151
151
|
|
152
152
|
## Validation outside a model
|
@@ -173,18 +173,18 @@ EmailValidator.valid?('narf@example.com', domain: 'foo.com') # boolean false
|
|
173
173
|
EmailValidator.invalid?('narf@example.com', domain: 'foo.com') # boolean true
|
174
174
|
```
|
175
175
|
|
176
|
-
###
|
176
|
+
### Strict mode
|
177
177
|
|
178
178
|
```ruby
|
179
|
-
EmailValidator.regexp(mode: :
|
180
|
-
EmailValidator.valid?('narf@example.com', mode: :
|
179
|
+
EmailValidator.regexp(mode: :strict) # returns the regex
|
180
|
+
EmailValidator.valid?('narf@example.com', mode: :strict) # boolean
|
181
181
|
```
|
182
182
|
|
183
|
-
###
|
183
|
+
### RFC mode
|
184
184
|
|
185
185
|
```ruby
|
186
|
-
EmailValidator.regexp(mode: :
|
187
|
-
EmailValidator.valid?('narf@example.com', mode: :
|
186
|
+
EmailValidator.regexp(mode: :rfc) # returns the regex
|
187
|
+
EmailValidator.valid?('narf@example.com', mode: :rfc) # boolean
|
188
188
|
```
|
189
189
|
|
190
190
|
## Thread safety
|
data/lib/email_validator.rb
CHANGED
@@ -88,8 +88,8 @@ class EmailValidator < ActiveModel::EachValidator
|
|
88
88
|
private
|
89
89
|
|
90
90
|
def parse_options(options)
|
91
|
-
# `:
|
92
|
-
options[:require_fqdn] = true if options[:require_fqdn].nil? && options[:mode] == :
|
91
|
+
# `:strict` mode enables `:require_fqdn`, unless it is already explicitly disabled
|
92
|
+
options[:require_fqdn] = true if options[:require_fqdn].nil? && options[:mode] == :strict
|
93
93
|
default_options.merge(options)
|
94
94
|
end
|
95
95
|
end
|
@@ -4,54 +4,54 @@ class DefaultUser < TestModel
|
|
4
4
|
validates :email, :email => true
|
5
5
|
end
|
6
6
|
|
7
|
-
class ModerateUser < TestModel
|
8
|
-
validates :email, :email => { :mode => :moderate }
|
9
|
-
end
|
10
|
-
|
11
7
|
class StrictUser < TestModel
|
12
8
|
validates :email, :email => { :mode => :strict }
|
13
9
|
end
|
14
10
|
|
15
|
-
class
|
16
|
-
validates :email, :email => { :
|
11
|
+
class RfcUser < TestModel
|
12
|
+
validates :email, :email => { :mode => :rfc }
|
17
13
|
end
|
18
14
|
|
19
|
-
class
|
20
|
-
validates :email, :email => { :allow_nil => true
|
15
|
+
class AllowNilDefaultUser < TestModel
|
16
|
+
validates :email, :email => { :allow_nil => true }
|
21
17
|
end
|
22
18
|
|
23
19
|
class AllowNilStrictUser < TestModel
|
24
20
|
validates :email, :email => { :allow_nil => true, :mode => :strict }
|
25
21
|
end
|
26
22
|
|
27
|
-
class
|
28
|
-
validates :email, :email => { :allow_nil =>
|
23
|
+
class AllowNilRfcUser < TestModel
|
24
|
+
validates :email, :email => { :allow_nil => true, :mode => :rfc }
|
29
25
|
end
|
30
26
|
|
31
|
-
class
|
32
|
-
validates :email, :email => { :allow_nil => false
|
27
|
+
class DisallowNilDefaultUser < TestModel
|
28
|
+
validates :email, :email => { :allow_nil => false }
|
33
29
|
end
|
34
30
|
|
35
31
|
class DisallowNilStrictUser < TestModel
|
36
32
|
validates :email, :email => { :allow_nil => false, :mode => :strict }
|
37
33
|
end
|
38
34
|
|
39
|
-
class
|
40
|
-
validates :email, :email => { :
|
35
|
+
class DisallowNilRfcUser < TestModel
|
36
|
+
validates :email, :email => { :allow_nil => false, :mode => :rfc }
|
41
37
|
end
|
42
38
|
|
43
39
|
class DomainStrictUser < TestModel
|
44
40
|
validates :email, :email => { :domain => 'example.com', :mode => :strict }
|
45
41
|
end
|
46
42
|
|
47
|
-
class
|
48
|
-
validates :email, :email => { :
|
43
|
+
class DomainRfcUser < TestModel
|
44
|
+
validates :email, :email => { :domain => 'example.com', :mode => :rfc }
|
49
45
|
end
|
50
46
|
|
51
47
|
class NonFqdnStrictUser < TestModel
|
52
48
|
validates :email, :email => { :require_fqdn => false, :mode => :strict }
|
53
49
|
end
|
54
50
|
|
51
|
+
class NonFqdnRfcUser < TestModel
|
52
|
+
validates :email, :email => { :require_fqdn => false, :mode => :rfc }
|
53
|
+
end
|
54
|
+
|
55
55
|
class DefaultUserWithMessage < TestModel
|
56
56
|
validates :email_address, :email => { :message => 'is not looking very good!' }
|
57
57
|
end
|
@@ -99,9 +99,9 @@ RSpec.describe EmailValidator do
|
|
99
99
|
valid_endable = valid_special_chars
|
100
100
|
invalid_includable = { :at => '@' }
|
101
101
|
whitespace = { :newline => "\n", :tab => "\t", :carriage_return => "\r", :space => ' ' }
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
strictly_invalid_includable = invalid_special_chars
|
103
|
+
strictly_invalid_beginable = strictly_invalid_includable.merge({ :dot => '.' })
|
104
|
+
strictly_invalid_endable = strictly_invalid_beginable
|
105
105
|
domain_invalid_beginable = invalid_special_chars.merge(valid_special_chars)
|
106
106
|
domain_invalid_endable = domain_invalid_beginable
|
107
107
|
domain_invalid_includable = domain_invalid_beginable.reject { |k, _v| k == :hyphen }
|
@@ -143,56 +143,56 @@ RSpec.describe EmailValidator do
|
|
143
143
|
'areallylongnameaasdfasdfasdfasdf@asdfasdfasdfasdfasdf.ab.cd.ef.gh.co.ca'
|
144
144
|
]).flatten.each do |email|
|
145
145
|
context 'when using defaults' do
|
146
|
-
it "#{email} should be valid" do
|
146
|
+
it "'#{email}' should be valid" do
|
147
147
|
expect(DefaultUser.new(:email => email)).to be_valid
|
148
148
|
end
|
149
149
|
|
150
|
-
it "#{email} should be valid using EmailValidator.valid?" do
|
150
|
+
it "'#{email}' should be valid using EmailValidator.valid?" do
|
151
151
|
expect(described_class).to be_valid(email)
|
152
152
|
end
|
153
153
|
|
154
|
-
it "#{email} should not be invalid using EmailValidator.invalid?" do
|
154
|
+
it "'#{email}' should not be invalid using EmailValidator.invalid?" do
|
155
155
|
expect(described_class).not_to be_invalid(email)
|
156
156
|
end
|
157
157
|
|
158
|
-
it "#{email} should match the regexp" do
|
158
|
+
it "'#{email}' should match the regexp" do
|
159
159
|
expect(!!(email.strip =~ described_class.regexp)).to be(true)
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
|
-
context 'when in `:
|
164
|
-
it "#{email} should be valid" do
|
165
|
-
expect(
|
163
|
+
context 'when in `:strict` mode' do
|
164
|
+
it "'#{email}' should be valid" do
|
165
|
+
expect(StrictUser.new(:email => email)).to be_valid
|
166
166
|
end
|
167
167
|
|
168
|
-
it "#{email} should be valid using EmailValidator.valid?" do
|
169
|
-
expect(described_class).to be_valid(email, :mode => :
|
168
|
+
it "'#{email}' should be valid using EmailValidator.valid?" do
|
169
|
+
expect(described_class).to be_valid(email, :mode => :strict)
|
170
170
|
end
|
171
171
|
|
172
|
-
it "#{email} should not be invalid using EmailValidator.valid?" do
|
173
|
-
expect(described_class).not_to be_invalid(email, :mode => :
|
172
|
+
it "'#{email}' should not be invalid using EmailValidator.valid?" do
|
173
|
+
expect(described_class).not_to be_invalid(email, :mode => :strict)
|
174
174
|
end
|
175
175
|
|
176
|
-
it "#{email} should match the regexp" do
|
177
|
-
expect(!!(email.strip =~ described_class.regexp(:mode => :
|
176
|
+
it "'#{email}' should match the regexp" do
|
177
|
+
expect(!!(email.strip =~ described_class.regexp(:mode => :strict))).to be(true)
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
181
|
-
context 'when in `:
|
182
|
-
it "#{email} should be valid" do
|
183
|
-
expect(
|
181
|
+
context 'when in `:rfc` mode' do
|
182
|
+
it "'#{email}' should be valid" do
|
183
|
+
expect(RfcUser.new(:email => email)).to be_valid
|
184
184
|
end
|
185
185
|
|
186
|
-
it "#{email} should be valid using EmailValidator.valid?" do
|
187
|
-
expect(described_class).to be_valid(email, :mode => :
|
186
|
+
it "'#{email}' should be valid using EmailValidator.valid?" do
|
187
|
+
expect(described_class).to be_valid(email, :mode => :rfc)
|
188
188
|
end
|
189
189
|
|
190
|
-
it "#{email} should not be invalid using EmailValidator.invalid?" do
|
191
|
-
expect(described_class).not_to be_invalid(email, :mode => :
|
190
|
+
it "'#{email}' should not be invalid using EmailValidator.invalid?" do
|
191
|
+
expect(described_class).not_to be_invalid(email, :mode => :rfc)
|
192
192
|
end
|
193
193
|
|
194
|
-
it "#{email} should match the regexp" do
|
195
|
-
expect(!!(email.strip =~ described_class.regexp(:mode => :
|
194
|
+
it "'#{email}' should match the regexp" do
|
195
|
+
expect(!!(email.strip =~ described_class.regexp(:mode => :rfc))).to be(true)
|
196
196
|
end
|
197
197
|
end
|
198
198
|
end
|
@@ -205,56 +205,56 @@ RSpec.describe EmailValidator do
|
|
205
205
|
'someuser@somehost'
|
206
206
|
].each do |email|
|
207
207
|
context 'when using defaults' do
|
208
|
-
it "#{email} should be valid" do
|
208
|
+
it "'#{email}' should be valid" do
|
209
209
|
expect(DefaultUser.new(:email => email)).to be_valid
|
210
210
|
end
|
211
211
|
|
212
|
-
it "#{email} should be valid using EmailValidator.valid?" do
|
212
|
+
it "'#{email}' should be valid using EmailValidator.valid?" do
|
213
213
|
expect(described_class).to be_valid(email)
|
214
214
|
end
|
215
215
|
|
216
|
-
it "#{email} should not be invalid using EmailValidator.invalid?" do
|
216
|
+
it "'#{email}' should not be invalid using EmailValidator.invalid?" do
|
217
217
|
expect(described_class).not_to be_invalid(email)
|
218
218
|
end
|
219
219
|
|
220
|
-
it "#{email} should match the regexp" do
|
220
|
+
it "'#{email}' should match the regexp" do
|
221
221
|
expect(!!(email.strip =~ described_class.regexp)).to be(true)
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
225
|
-
context 'when in `:
|
226
|
-
it "#{email} should not be valid" do
|
227
|
-
expect(
|
225
|
+
context 'when in `:strict` mode' do
|
226
|
+
it "'#{email}' should not be valid" do
|
227
|
+
expect(StrictUser.new(:email => email)).not_to be_valid
|
228
228
|
end
|
229
229
|
|
230
|
-
it "#{email} should not be valid using EmailValidator.valid?" do
|
231
|
-
expect(described_class).not_to be_valid(email, :mode => :
|
230
|
+
it "'#{email}' should not be valid using EmailValidator.valid?" do
|
231
|
+
expect(described_class).not_to be_valid(email, :mode => :strict)
|
232
232
|
end
|
233
233
|
|
234
|
-
it "#{email} should be invalid using EmailValidator.invalid?" do
|
235
|
-
expect(described_class).to be_invalid(email, :mode => :
|
234
|
+
it "'#{email}' should be invalid using EmailValidator.invalid?" do
|
235
|
+
expect(described_class).to be_invalid(email, :mode => :strict)
|
236
236
|
end
|
237
237
|
|
238
|
-
it "#{email} should not match the regexp" do
|
239
|
-
expect(!!(email.strip =~ described_class.regexp(:mode => :
|
238
|
+
it "'#{email}' should not match the regexp" do
|
239
|
+
expect(!!(email.strip =~ described_class.regexp(:mode => :strict))).to be(false)
|
240
240
|
end
|
241
241
|
end
|
242
242
|
|
243
|
-
context 'when in `:
|
244
|
-
it "#{email} should be valid" do
|
245
|
-
expect(
|
243
|
+
context 'when in `:rfc` mode' do
|
244
|
+
it "'#{email}' should be valid" do
|
245
|
+
expect(RfcUser.new(:email => email)).to be_valid
|
246
246
|
end
|
247
247
|
|
248
|
-
it "#{email} should be valid using EmailValidator.valid?" do
|
249
|
-
expect(described_class).to be_valid(email, :mode => :
|
248
|
+
it "'#{email}' should be valid using EmailValidator.valid?" do
|
249
|
+
expect(described_class).to be_valid(email, :mode => :rfc)
|
250
250
|
end
|
251
251
|
|
252
|
-
it "#{email} should not be invalid using EmailValidator.invalid?" do
|
253
|
-
expect(described_class).not_to be_invalid(email, :mode => :
|
252
|
+
it "'#{email}' should not be invalid using EmailValidator.invalid?" do
|
253
|
+
expect(described_class).not_to be_invalid(email, :mode => :rfc)
|
254
254
|
end
|
255
255
|
|
256
|
-
it "#{email} should match the regexp" do
|
257
|
-
expect(!!(email.strip =~ described_class.regexp(:mode => :
|
256
|
+
it "'#{email}' should match the regexp" do
|
257
|
+
expect(!!(email.strip =~ described_class.regexp(:mode => :rfc))).to be(true)
|
258
258
|
end
|
259
259
|
end
|
260
260
|
end
|
@@ -266,56 +266,56 @@ RSpec.describe EmailValidator do
|
|
266
266
|
'bracketed-and-labeled-IPv6@[IPv6:abcd:ef01:1234:5678:9abc:def0:1234:5678]'
|
267
267
|
].each do |email|
|
268
268
|
context 'when using defaults' do
|
269
|
-
it "#{email} should be valid" do
|
269
|
+
it "'#{email}' should be valid" do
|
270
270
|
expect(DefaultUser.new(:email => email)).to be_valid
|
271
271
|
end
|
272
272
|
|
273
|
-
it "#{email} should be valid using EmailValidator.valid?" do
|
273
|
+
it "'#{email}' should be valid using EmailValidator.valid?" do
|
274
274
|
expect(described_class).to be_valid(email)
|
275
275
|
end
|
276
276
|
|
277
|
-
it "#{email} should not be invalid using EmailValidator.invalid?" do
|
277
|
+
it "'#{email}' should not be invalid using EmailValidator.invalid?" do
|
278
278
|
expect(described_class).not_to be_invalid(email)
|
279
279
|
end
|
280
280
|
|
281
|
-
it "#{email} should match the regexp" do
|
281
|
+
it "'#{email}' should match the regexp" do
|
282
282
|
expect(!!(email.strip =~ described_class.regexp)).to be(true)
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
286
|
-
context 'when in `:
|
287
|
-
it "#{email} should not be valid" do
|
288
|
-
expect(
|
286
|
+
context 'when in `:strict` mode' do
|
287
|
+
it "'#{email}' should not be valid" do
|
288
|
+
expect(StrictUser.new(:email => email)).not_to be_valid
|
289
289
|
end
|
290
290
|
|
291
|
-
it "#{email} should not be valid using EmailValidator.valid?" do
|
292
|
-
expect(described_class).not_to be_valid(email, :mode => :
|
291
|
+
it "'#{email}' should not be valid using EmailValidator.valid?" do
|
292
|
+
expect(described_class).not_to be_valid(email, :mode => :strict)
|
293
293
|
end
|
294
294
|
|
295
|
-
it "#{email} should be invalid using EmailValidator.invalid?" do
|
296
|
-
expect(described_class).to be_invalid(email, :mode => :
|
295
|
+
it "'#{email}' should be invalid using EmailValidator.invalid?" do
|
296
|
+
expect(described_class).to be_invalid(email, :mode => :strict)
|
297
297
|
end
|
298
298
|
|
299
|
-
it "#{email} should not match the
|
300
|
-
expect(!!(email.strip =~ described_class.regexp(:mode => :
|
299
|
+
it "'#{email}' should not match the regexp" do
|
300
|
+
expect(!!(email.strip =~ described_class.regexp(:mode => :strict))).to be(false)
|
301
301
|
end
|
302
302
|
end
|
303
303
|
|
304
|
-
context 'when in `:
|
305
|
-
it "#{email} should be valid" do
|
306
|
-
expect(
|
304
|
+
context 'when in `:rfc` mode' do
|
305
|
+
it "'#{email}' should be valid" do
|
306
|
+
expect(RfcUser.new(:email => email)).to be_valid
|
307
307
|
end
|
308
308
|
|
309
|
-
it "#{email} should be valid using EmailValidator.valid?" do
|
310
|
-
expect(described_class).to be_valid(email, :mode => :
|
309
|
+
it "'#{email}' should be valid using EmailValidator.valid?" do
|
310
|
+
expect(described_class).to be_valid(email, :mode => :rfc)
|
311
311
|
end
|
312
312
|
|
313
|
-
it "#{email} should not be invalid using EmailValidator.invalid?" do
|
314
|
-
expect(described_class).not_to be_invalid(email, :mode => :
|
313
|
+
it "'#{email}' should not be invalid using EmailValidator.invalid?" do
|
314
|
+
expect(described_class).not_to be_invalid(email, :mode => :rfc)
|
315
315
|
end
|
316
316
|
|
317
|
-
it "#{email} should match the
|
318
|
-
expect(!!(email.strip =~ described_class.regexp(:mode => :
|
317
|
+
it "'#{email}' should match the regexp" do
|
318
|
+
expect(!!(email.strip =~ described_class.regexp(:mode => :rfc))).to be(true)
|
319
319
|
end
|
320
320
|
end
|
321
321
|
end
|
@@ -350,56 +350,56 @@ RSpec.describe EmailValidator do
|
|
350
350
|
"user@example.com<script>alert('hello')</script>"
|
351
351
|
]).flatten.each do |email|
|
352
352
|
context 'when using defaults' do
|
353
|
-
it "#{email} should be valid" do
|
353
|
+
it "'#{email}' should be valid" do
|
354
354
|
expect(DefaultUser.new(:email => email)).to be_valid
|
355
355
|
end
|
356
356
|
|
357
|
-
it "#{email} should be valid using EmailValidator.valid?" do
|
357
|
+
it "'#{email}' should be valid using EmailValidator.valid?" do
|
358
358
|
expect(described_class).to be_valid(email)
|
359
359
|
end
|
360
360
|
|
361
|
-
it "#{email} should not be invalid using EmailValidator.invalid?" do
|
361
|
+
it "'#{email}' should not be invalid using EmailValidator.invalid?" do
|
362
362
|
expect(described_class).not_to be_invalid(email)
|
363
363
|
end
|
364
364
|
|
365
|
-
it "#{email} should match the regexp" do
|
365
|
+
it "'#{email}' should match the regexp" do
|
366
366
|
expect(!!(email.strip =~ described_class.regexp)).to be(true)
|
367
367
|
end
|
368
368
|
end
|
369
369
|
|
370
|
-
context 'when in `:
|
371
|
-
it "#{email} should not be valid" do
|
372
|
-
expect(
|
370
|
+
context 'when in `:strict` mode' do
|
371
|
+
it "'#{email}' should not be valid" do
|
372
|
+
expect(StrictUser.new(:email => email)).not_to be_valid
|
373
373
|
end
|
374
374
|
|
375
|
-
it "#{email} should not be valid using EmailValidator.valid?" do
|
376
|
-
expect(described_class).not_to be_valid(email, :mode => :
|
375
|
+
it "'#{email}' should not be valid using EmailValidator.valid?" do
|
376
|
+
expect(described_class).not_to be_valid(email, :mode => :strict)
|
377
377
|
end
|
378
378
|
|
379
|
-
it "#{email} should be invalid using EmailValidator.invalid?" do
|
380
|
-
expect(described_class).to be_invalid(email, :mode => :
|
379
|
+
it "'#{email}' should be invalid using EmailValidator.invalid?" do
|
380
|
+
expect(described_class).to be_invalid(email, :mode => :strict)
|
381
381
|
end
|
382
382
|
|
383
|
-
it "#{email} should not match the
|
384
|
-
expect(!!(email.strip =~ described_class.regexp(:mode => :
|
383
|
+
it "'#{email}' should not match the regexp" do
|
384
|
+
expect(!!(email.strip =~ described_class.regexp(:mode => :strict))).to be(false)
|
385
385
|
end
|
386
386
|
end
|
387
387
|
|
388
|
-
context 'when in `:
|
389
|
-
it "#{email} should not be valid" do
|
390
|
-
expect(
|
388
|
+
context 'when in `:rfc` mode' do
|
389
|
+
it "'#{email}' should not be valid" do
|
390
|
+
expect(RfcUser.new(:email => email)).not_to be_valid
|
391
391
|
end
|
392
392
|
|
393
|
-
it "#{email} should not be valid using EmailValidator.valid?" do
|
394
|
-
expect(described_class).not_to be_valid(email, :mode => :
|
393
|
+
it "'#{email}' should not be valid using EmailValidator.valid?" do
|
394
|
+
expect(described_class).not_to be_valid(email, :mode => :rfc)
|
395
395
|
end
|
396
396
|
|
397
|
-
it "#{email} should be invalid using EmailValidator.invalid?" do
|
398
|
-
expect(described_class).to be_invalid(email, :mode => :
|
397
|
+
it "'#{email}' should be invalid using EmailValidator.invalid?" do
|
398
|
+
expect(described_class).to be_invalid(email, :mode => :rfc)
|
399
399
|
end
|
400
400
|
|
401
|
-
it "#{email} should not match the
|
402
|
-
expect(!!(email.strip =~ described_class.regexp(:mode => :
|
401
|
+
it "'#{email}' should not match the regexp" do
|
402
|
+
expect(!!(email.strip =~ described_class.regexp(:mode => :rfc))).to be(false)
|
403
403
|
end
|
404
404
|
end
|
405
405
|
end
|
@@ -443,56 +443,56 @@ RSpec.describe EmailValidator do
|
|
443
443
|
"
|
444
444
|
]).flatten.each do |email|
|
445
445
|
context 'when using defaults' do
|
446
|
-
it "#{email} should not be valid" do
|
446
|
+
it "'#{email}' should not be valid" do
|
447
447
|
expect(DefaultUser.new(:email => email)).not_to be_valid
|
448
448
|
end
|
449
449
|
|
450
|
-
it "#{email} should not be valid using EmailValidator.valid?" do
|
450
|
+
it "'#{email}' should not be valid using EmailValidator.valid?" do
|
451
451
|
expect(described_class).not_to be_valid(email)
|
452
452
|
end
|
453
453
|
|
454
|
-
it "#{email} should be invalid using EmailValidator.invalid?" do
|
454
|
+
it "'#{email}' should be invalid using EmailValidator.invalid?" do
|
455
455
|
expect(described_class).to be_invalid(email)
|
456
456
|
end
|
457
457
|
|
458
|
-
it "#{email} should not match the regexp" do
|
458
|
+
it "'#{email}' should not match the regexp" do
|
459
459
|
expect(!!(email =~ described_class.regexp)).to be(false)
|
460
460
|
end
|
461
461
|
end
|
462
462
|
|
463
|
-
context 'when in `:
|
464
|
-
it "#{email} should not be valid" do
|
465
|
-
expect(
|
463
|
+
context 'when in `:strict` mode' do
|
464
|
+
it "'#{email}' should not be valid" do
|
465
|
+
expect(StrictUser.new(:email => email)).not_to be_valid
|
466
466
|
end
|
467
467
|
|
468
|
-
it "#{email} should not be valid using EmailValidator.valid?" do
|
469
|
-
expect(described_class).not_to be_valid(email, :mode => :
|
468
|
+
it "'#{email}' should not be valid using EmailValidator.valid?" do
|
469
|
+
expect(described_class).not_to be_valid(email, :mode => :strict)
|
470
470
|
end
|
471
471
|
|
472
|
-
it "#{email} should be invalid using EmailValidator.invalid?" do
|
473
|
-
expect(described_class).to be_invalid(email, :mode => :
|
472
|
+
it "'#{email}' should be invalid using EmailValidator.invalid?" do
|
473
|
+
expect(described_class).to be_invalid(email, :mode => :strict)
|
474
474
|
end
|
475
475
|
|
476
|
-
it "#{email} should not match the
|
477
|
-
expect(!!(email =~ described_class.regexp(:mode => :
|
476
|
+
it "'#{email}' should not match the regexp" do
|
477
|
+
expect(!!(email =~ described_class.regexp(:mode => :strict))).to be(false)
|
478
478
|
end
|
479
479
|
end
|
480
480
|
|
481
|
-
context 'when in `:
|
482
|
-
it "#{email} should not be valid" do
|
483
|
-
expect(
|
481
|
+
context 'when in `:rfc` mode' do
|
482
|
+
it "'#{email}' should not be valid" do
|
483
|
+
expect(RfcUser.new(:email => email)).not_to be_valid
|
484
484
|
end
|
485
485
|
|
486
|
-
it "#{email} should not be valid using EmailValidator.valid?" do
|
487
|
-
expect(described_class).not_to be_valid(email, :mode => :
|
486
|
+
it "'#{email}' should not be valid using EmailValidator.valid?" do
|
487
|
+
expect(described_class).not_to be_valid(email, :mode => :rfc)
|
488
488
|
end
|
489
489
|
|
490
|
-
it "#{email} should be invalid using EmailValidator.invalid?" do
|
491
|
-
expect(described_class).to be_invalid(email, :mode => :
|
490
|
+
it "'#{email}' should be invalid using EmailValidator.invalid?" do
|
491
|
+
expect(described_class).to be_invalid(email, :mode => :rfc)
|
492
492
|
end
|
493
493
|
|
494
|
-
it "#{email} should not match the
|
495
|
-
expect(!!(email =~ described_class.regexp(:mode => :
|
494
|
+
it "'#{email}' should not match the regexp" do
|
495
|
+
expect(!!(email =~ described_class.regexp(:mode => :rfc))).to be(false)
|
496
496
|
end
|
497
497
|
end
|
498
498
|
end
|
@@ -508,67 +508,67 @@ RSpec.describe EmailValidator do
|
|
508
508
|
'missing-at-sign.dev'
|
509
509
|
].each do |email|
|
510
510
|
context 'when using defaults' do
|
511
|
-
it "#{email} should not be valid" do
|
511
|
+
it "'#{email}' should not be valid" do
|
512
512
|
expect(DefaultUser.new(:email => email)).not_to be_valid
|
513
513
|
end
|
514
514
|
|
515
|
-
it "#{email} should not be valid using EmailValidator.valid?" do
|
515
|
+
it "'#{email}' should not be valid using EmailValidator.valid?" do
|
516
516
|
expect(described_class).not_to be_valid(email)
|
517
517
|
end
|
518
518
|
|
519
|
-
it "#{email} should be invalid using EmailValidator.invalid?" do
|
519
|
+
it "'#{email}' should be invalid using EmailValidator.invalid?" do
|
520
520
|
expect(described_class).to be_invalid(email)
|
521
521
|
end
|
522
522
|
|
523
|
-
it "#{email} should not match the regexp" do
|
523
|
+
it "'#{email}' should not match the regexp" do
|
524
524
|
expect(!!(email.strip =~ described_class.regexp)).to be(false)
|
525
525
|
end
|
526
526
|
end
|
527
527
|
|
528
|
-
context 'when in `:
|
529
|
-
it "#{email} should not be valid" do
|
530
|
-
expect(
|
528
|
+
context 'when in `:strict` mode' do
|
529
|
+
it "'#{email}' should not be valid" do
|
530
|
+
expect(StrictUser.new(:email => email)).not_to be_valid
|
531
531
|
end
|
532
532
|
|
533
|
-
it "#{email} should not be valid using EmailValidator.valid?" do
|
534
|
-
expect(described_class).not_to be_valid(email, :mode => :
|
533
|
+
it "'#{email}' should not be valid using EmailValidator.valid?" do
|
534
|
+
expect(described_class).not_to be_valid(email, :mode => :strict)
|
535
535
|
end
|
536
536
|
|
537
|
-
it "#{email} should be invalid using EmailValidator.invalid?" do
|
538
|
-
expect(described_class).to be_invalid(email, :mode => :
|
537
|
+
it "'#{email}' should be invalid using EmailValidator.invalid?" do
|
538
|
+
expect(described_class).to be_invalid(email, :mode => :strict)
|
539
539
|
end
|
540
540
|
|
541
|
-
it "#{email} should not match the
|
542
|
-
expect(!!(email.strip =~ described_class.regexp(:mode => :
|
541
|
+
it "'#{email}' should not match the regexp" do
|
542
|
+
expect(!!(email.strip =~ described_class.regexp(:mode => :strict))).to be(false)
|
543
543
|
end
|
544
544
|
end
|
545
545
|
|
546
|
-
context 'when in `:
|
547
|
-
it "#{email} should not be valid" do
|
548
|
-
expect(
|
546
|
+
context 'when in `:rfc` mode' do
|
547
|
+
it "'#{email}' should not be valid" do
|
548
|
+
expect(RfcUser.new(:email => email)).not_to be_valid
|
549
549
|
end
|
550
550
|
|
551
|
-
it "#{email} should not be valid using EmailValidator.valid?" do
|
552
|
-
expect(described_class).not_to be_valid(email, :mode => :
|
551
|
+
it "'#{email}' should not be valid using EmailValidator.valid?" do
|
552
|
+
expect(described_class).not_to be_valid(email, :mode => :rfc)
|
553
553
|
end
|
554
554
|
|
555
|
-
it "#{email} should be invalid using EmailValidator.invalid?" do
|
556
|
-
expect(described_class).to be_invalid(email, :mode => :
|
555
|
+
it "'#{email}' should be invalid using EmailValidator.invalid?" do
|
556
|
+
expect(described_class).to be_invalid(email, :mode => :rfc)
|
557
557
|
end
|
558
558
|
|
559
|
-
it "#{email} should not match the
|
560
|
-
expect(!!(email.strip =~ described_class.regexp(:mode => :
|
559
|
+
it "'#{email}' should not match the regexp" do
|
560
|
+
expect(!!(email.strip =~ described_class.regexp(:mode => :rfc))).to be(false)
|
561
561
|
end
|
562
562
|
end
|
563
563
|
end
|
564
564
|
end
|
565
565
|
|
566
|
-
context 'when given the
|
567
|
-
|
566
|
+
context 'when given the strictly invalid email' do
|
567
|
+
strictly_invalid_includable.map { |k, v| [
|
568
568
|
"include-#{v}-#{k}@invalid-characters-in-local.dev"
|
569
|
-
]}.concat(
|
569
|
+
]}.concat(strictly_invalid_beginable.map { |k, v| [
|
570
570
|
"#{v}start-with-#{k}@invalid-characters-in-local.dev"
|
571
|
-
]}).concat(
|
571
|
+
]}).concat(strictly_invalid_endable.map { |k, v| [
|
572
572
|
"end-with-#{k}#{v}@invalid-characters-in-local.dev"
|
573
573
|
]}).concat([
|
574
574
|
'user..-with-double-dots@example.com',
|
@@ -593,39 +593,39 @@ RSpec.describe EmailValidator do
|
|
593
593
|
end
|
594
594
|
end
|
595
595
|
|
596
|
-
context 'when in `:
|
596
|
+
context 'when in `:strict` mode' do
|
597
597
|
it "#{email.strip} in a model should be valid" do
|
598
|
-
expect(
|
598
|
+
expect(StrictUser.new(:email => email)).not_to be_valid
|
599
599
|
end
|
600
600
|
|
601
601
|
it "#{email.strip} should not be valid using EmailValidator.valid?" do
|
602
|
-
expect(described_class).not_to be_valid(email, :mode => :
|
602
|
+
expect(described_class).not_to be_valid(email, :mode => :strict)
|
603
603
|
end
|
604
604
|
|
605
605
|
it "#{email.strip} should be invalid using EmailValidator.invalid?" do
|
606
|
-
expect(described_class).to be_invalid(email, :mode => :
|
606
|
+
expect(described_class).to be_invalid(email, :mode => :strict)
|
607
607
|
end
|
608
608
|
|
609
|
-
it "#{email.strip} should not match the
|
610
|
-
expect(!!(email =~ described_class.regexp(:mode => :
|
609
|
+
it "#{email.strip} should not match the regexp" do
|
610
|
+
expect(!!(email =~ described_class.regexp(:mode => :strict))).to be(false)
|
611
611
|
end
|
612
612
|
end
|
613
613
|
|
614
|
-
context 'when in `:
|
614
|
+
context 'when in `:rfc` mode' do
|
615
615
|
it "#{email.strip} in a model should not be valid" do
|
616
|
-
expect(
|
616
|
+
expect(RfcUser.new(:email => email)).not_to be_valid
|
617
617
|
end
|
618
618
|
|
619
619
|
it "#{email.strip} should not be valid using EmailValidator.valid?" do
|
620
|
-
expect(described_class).not_to be_valid(email, :mode => :
|
620
|
+
expect(described_class).not_to be_valid(email, :mode => :rfc)
|
621
621
|
end
|
622
622
|
|
623
623
|
it "#{email.strip} should be invalid using EmailValidator.invalid?" do
|
624
|
-
expect(described_class).to be_invalid(email, :mode => :
|
624
|
+
expect(described_class).to be_invalid(email, :mode => :rfc)
|
625
625
|
end
|
626
626
|
|
627
|
-
it "#{email.strip} should not match the
|
628
|
-
expect(!!(email =~ described_class.regexp(:mode => :
|
627
|
+
it "#{email.strip} should not match the regexp" do
|
628
|
+
expect(!!(email =~ described_class.regexp(:mode => :rfc))).to be(false)
|
629
629
|
end
|
630
630
|
end
|
631
631
|
end
|
@@ -651,11 +651,11 @@ RSpec.describe EmailValidator do
|
|
651
651
|
end
|
652
652
|
end
|
653
653
|
|
654
|
-
context 'when in `
|
655
|
-
let(:opts) { { :require_fqdn => false, :mode => :
|
654
|
+
context 'when in `:strict` mode' do
|
655
|
+
let(:opts) { { :require_fqdn => false, :mode => :strict } }
|
656
656
|
|
657
657
|
it 'is valid' do
|
658
|
-
expect(
|
658
|
+
expect(NonFqdnStrictUser.new(:email => email)).to be_valid
|
659
659
|
end
|
660
660
|
|
661
661
|
it 'is valid using EmailValidator.valid?' do
|
@@ -671,11 +671,11 @@ RSpec.describe EmailValidator do
|
|
671
671
|
end
|
672
672
|
end
|
673
673
|
|
674
|
-
context 'when in `:
|
675
|
-
let(:opts) { { :require_fqdn => false, :mode => :
|
674
|
+
context 'when in `:rfc` mode' do
|
675
|
+
let(:opts) { { :require_fqdn => false, :mode => :rfc } }
|
676
676
|
|
677
|
-
it 'is valid
|
678
|
-
expect(
|
677
|
+
it 'is valid' do
|
678
|
+
expect(NonFqdnRfcUser.new(:email => email)).to be_valid
|
679
679
|
end
|
680
680
|
|
681
681
|
it 'is valid using EmailValidator.valid?' do
|
@@ -686,7 +686,7 @@ RSpec.describe EmailValidator do
|
|
686
686
|
expect(described_class).not_to be_invalid(email, opts)
|
687
687
|
end
|
688
688
|
|
689
|
-
it '
|
689
|
+
it 'matches the regexp' do
|
690
690
|
expect(!!(email =~ described_class.regexp(opts))).to be(true)
|
691
691
|
end
|
692
692
|
end
|
@@ -696,7 +696,7 @@ RSpec.describe EmailValidator do
|
|
696
696
|
let(:email) { 'someuser@somehost.somedomain' }
|
697
697
|
|
698
698
|
it 'is valid' do
|
699
|
-
expect(
|
699
|
+
expect(NonFqdnStrictUser.new(:email => email)).to be_valid
|
700
700
|
end
|
701
701
|
|
702
702
|
# rubocop:disable RSpec/PredicateMatcher
|
@@ -713,8 +713,8 @@ RSpec.describe EmailValidator do
|
|
713
713
|
expect(!!(email =~ described_class.regexp(opts))).to be(true)
|
714
714
|
end
|
715
715
|
|
716
|
-
context 'when in `:
|
717
|
-
let(:opts) { { :require_fqdn => false, :mode => :
|
716
|
+
context 'when in `:rfc` mode' do
|
717
|
+
let(:opts) { { :require_fqdn => false, :mode => :rfc } }
|
718
718
|
|
719
719
|
# rubocop:disable RSpec/PredicateMatcher
|
720
720
|
it 'is valid using EmailValidator.valid?' do
|
@@ -726,11 +726,11 @@ RSpec.describe EmailValidator do
|
|
726
726
|
end
|
727
727
|
# rubocop:enable RSpec/PredicateMatcher
|
728
728
|
|
729
|
-
it 'is valid
|
730
|
-
expect(
|
729
|
+
it 'is valid' do
|
730
|
+
expect(NonFqdnRfcUser.new(:email => email)).to be_valid
|
731
731
|
end
|
732
732
|
|
733
|
-
it '
|
733
|
+
it 'matches the regexp' do
|
734
734
|
expect(!!(email =~ described_class.regexp(opts))).to be(true)
|
735
735
|
end
|
736
736
|
end
|
@@ -740,7 +740,7 @@ RSpec.describe EmailValidator do
|
|
740
740
|
let(:opts) { { :domain => domain } }
|
741
741
|
|
742
742
|
it 'is not valid' do
|
743
|
-
expect(
|
743
|
+
expect(DomainStrictUser.new(:email => email)).not_to be_valid
|
744
744
|
end
|
745
745
|
|
746
746
|
it 'is not valid using EmailValidator.valid?' do
|
@@ -755,8 +755,8 @@ RSpec.describe EmailValidator do
|
|
755
755
|
expect(!!(email =~ described_class.regexp(opts))).to be(false)
|
756
756
|
end
|
757
757
|
|
758
|
-
context 'when in `:
|
759
|
-
let(:opts) { { :domain => domain, :require_fqdn => false, :mode => :
|
758
|
+
context 'when in `:rfc` mode' do
|
759
|
+
let(:opts) { { :domain => domain, :require_fqdn => false, :mode => :rfc } }
|
760
760
|
|
761
761
|
it 'is not valid using EmailValidator.valid?' do
|
762
762
|
expect(described_class).not_to be_valid(email, opts)
|
@@ -767,7 +767,7 @@ RSpec.describe EmailValidator do
|
|
767
767
|
end
|
768
768
|
|
769
769
|
it 'is not valid' do
|
770
|
-
expect(
|
770
|
+
expect(DomainRfcUser.new(:email => email)).not_to be_valid
|
771
771
|
end
|
772
772
|
|
773
773
|
it 'does not match the regexp' do
|
@@ -817,55 +817,68 @@ RSpec.describe EmailValidator do
|
|
817
817
|
end
|
818
818
|
|
819
819
|
describe 'limited to a domain' do
|
820
|
-
context 'when in `:
|
820
|
+
context 'when in `:strict` mode' do
|
821
821
|
it 'is not valid with mismatched domain' do
|
822
|
-
expect(
|
822
|
+
expect(DomainStrictUser.new(:email => 'user@not-matching.io')).not_to be_valid
|
823
823
|
end
|
824
824
|
|
825
825
|
it 'is valid with matching domain' do
|
826
|
-
expect(
|
826
|
+
expect(DomainStrictUser.new(:email => 'user@example.com')).to be_valid
|
827
827
|
end
|
828
828
|
|
829
829
|
it 'does not interpret the dot as any character' do
|
830
|
-
expect(
|
830
|
+
expect(DomainStrictUser.new(:email => 'user@example-com')).not_to be_valid
|
831
831
|
end
|
832
832
|
end
|
833
833
|
|
834
|
-
context 'when in
|
834
|
+
context 'when in `:rfc` mode' do
|
835
835
|
it 'does not interpret the dot as any character' do
|
836
|
-
expect(
|
836
|
+
expect(DomainRfcUser.new(:email => 'user@example-com')).not_to be_valid
|
837
837
|
end
|
838
838
|
|
839
839
|
it 'is valid with matching domain' do
|
840
|
-
expect(
|
840
|
+
expect(DomainRfcUser.new(:email => 'user@example.com')).to be_valid
|
841
841
|
end
|
842
842
|
|
843
843
|
it 'is not valid with mismatched domain' do
|
844
|
-
expect(
|
844
|
+
expect(DomainRfcUser.new(:email => 'user@not-matching.io')).not_to be_valid
|
845
845
|
end
|
846
846
|
end
|
847
847
|
end
|
848
848
|
|
849
849
|
describe 'default_options' do
|
850
|
-
let(:
|
850
|
+
let(:valid_email) { 'valid-email@localhost.localdomain' }
|
851
|
+
let(:invalid_email) { 'invalid email@localhost.localdomain' }
|
851
852
|
|
852
|
-
it 'validates using `:loose` mode' do
|
853
|
-
expect(DefaultUser.new(:email =>
|
853
|
+
it 'validates valid using `:loose` mode' do
|
854
|
+
expect(DefaultUser.new(:email => valid_email)).to be_valid
|
854
855
|
end
|
855
856
|
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
it 'validates using `:moderate` mode' do
|
860
|
-
expect(DefaultUser.new(:email => email)).not_to be_valid
|
861
|
-
end
|
857
|
+
it 'invalidates invalid using `:loose` mode' do
|
858
|
+
expect(DefaultUser.new(:email => invalid_email)).to be_invalid
|
862
859
|
end
|
863
860
|
|
864
861
|
context 'when `email_validator/strict` has been required' do
|
865
862
|
before { require 'email_validator/strict' }
|
866
863
|
|
867
|
-
it '
|
868
|
-
expect(DefaultUser.new(:email =>
|
864
|
+
it 'validates valid using `:strict` mode' do
|
865
|
+
expect(DefaultUser.new(:email => valid_email)).to be_valid
|
866
|
+
end
|
867
|
+
|
868
|
+
it 'invalidates invalid using `:strict` mode' do
|
869
|
+
expect(DefaultUser.new(:email => invalid_email)).to be_invalid
|
870
|
+
end
|
871
|
+
end
|
872
|
+
|
873
|
+
context 'when `email_validator/rfc` has been required' do
|
874
|
+
before { require 'email_validator/rfc' }
|
875
|
+
|
876
|
+
it 'validates valid using `:rfc` mode' do
|
877
|
+
expect(DefaultUser.new(:email => valid_email)).to be_valid
|
878
|
+
end
|
879
|
+
|
880
|
+
it 'invalidates invalid using `:rfc` mode' do
|
881
|
+
expect(DefaultUser.new(:email => invalid_email)).to be_invalid
|
869
882
|
end
|
870
883
|
end
|
871
884
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Alexander
|
@@ -41,7 +41,8 @@ files:
|
|
41
41
|
- spec/email_validator_spec.rb
|
42
42
|
- spec/spec_helper.rb
|
43
43
|
homepage: https://github.com/K-and-R/email_validator
|
44
|
-
licenses:
|
44
|
+
licenses:
|
45
|
+
- MIT
|
45
46
|
metadata: {}
|
46
47
|
post_install_message:
|
47
48
|
rdoc_options: []
|