-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* develop: Bump version to `2.2.3` Fix regexp for numeric domains (fixes #72) Add `EmailValidator::Error` class, raise `EmailValidator::Error` when invalid `mode` Add checks for double dash in domain Fix specs for numeric-only domains labels Add checks for numeric-only TLDs in tests Add tests to ensure that `regexp` returns expected value Bump y18n from 3.2.1 to 3.2.2 Add failing test: strict mode should accept numbers only domains Update .travis.yml
- Loading branch information
Showing
7 changed files
with
113 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
language: ruby | ||
arch: | ||
- amd64 | ||
- ppc64le | ||
|
||
rvm: | ||
- 2.4.7 | ||
- 2.4.10 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,7 +146,8 @@ class DefaultUserWithMessage < TestModel | |
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]' | ||
'[email protected]', | ||
'[email protected]' | ||
]).flatten.each do |email| | ||
context 'when using defaults' do | ||
it "'#{email}' should be valid" do | ||
|
@@ -289,20 +290,20 @@ class DefaultUserWithMessage < TestModel | |
end | ||
|
||
context 'when in `:strict` mode' do | ||
it "'#{email}' should not be valid" do | ||
expect(StrictUser.new(:email => email)).not_to be_valid | ||
it "'#{email}' should be valid" do | ||
expect(StrictUser.new(:email => email)).to be_valid | ||
end | ||
|
||
it "'#{email}' should not be valid using EmailValidator.valid?" do | ||
expect(described_class).not_to be_valid(email, :mode => :strict) | ||
it "'#{email}' should be valid using EmailValidator.valid?" do | ||
expect(described_class).to be_valid(email, :mode => :strict) | ||
end | ||
|
||
it "'#{email}' should be invalid using EmailValidator.invalid?" do | ||
expect(described_class).to be_invalid(email, :mode => :strict) | ||
it "'#{email}' should be not invalid using EmailValidator.invalid?" do | ||
expect(described_class).not_to be_invalid(email, :mode => :strict) | ||
end | ||
|
||
it "'#{email}' should not match the regexp" do | ||
expect(!!(email.strip =~ described_class.regexp(:mode => :strict))).to be(false) | ||
it "'#{email}' should match the regexp" do | ||
expect(!!(email.strip =~ described_class.regexp(:mode => :strict))).to be(true) | ||
end | ||
end | ||
|
||
|
@@ -476,6 +477,7 @@ class DefaultUserWithMessage < TestModel | |
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.dev', | ||
"domain-too-long@t#{".#{'o' * 63}" * 5}.long", | ||
"[email protected]<script>alert('hello')</script>" | ||
|
@@ -703,7 +705,8 @@ class DefaultUserWithMessage < TestModel | |
]}).concat([ | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]' | ||
'[email protected]', | ||
'[email protected]' | ||
]).flatten.each do |email| | ||
context 'when using defaults' do | ||
it "#{email.strip} in a model should be valid" do | ||
|
@@ -781,23 +784,24 @@ class DefaultUserWithMessage < TestModel | |
end | ||
end | ||
|
||
# Strict mode enables `require_fqdn` anyway | ||
context 'when in `:strict` mode' do | ||
let(:opts) { { :require_fqdn => false, :mode => :strict } } | ||
|
||
it 'is valid' do | ||
expect(NonFqdnStrictUser.new(:email => email)).to be_valid | ||
it 'is not valid' do | ||
expect(NonFqdnStrictUser.new(:email => email)).not_to be_valid | ||
end | ||
|
||
it 'is valid using EmailValidator.valid?' do | ||
expect(described_class).to be_valid(email, opts) | ||
it 'is not valid using EmailValidator.valid?' do | ||
expect(described_class).not_to be_valid(email, opts) | ||
end | ||
|
||
it 'is not invalid using EmailValidator.invalid?' do | ||
expect(described_class).not_to be_invalid(email, opts) | ||
it 'is invalid using EmailValidator.invalid?' do | ||
expect(described_class).to be_invalid(email, opts) | ||
end | ||
|
||
it 'matches the regexp' do | ||
expect(!!(email =~ described_class.regexp(opts))).to be(true) | ||
expect(!!(email =~ described_class.regexp(opts))).to be(false) | ||
end | ||
end | ||
|
||
|
@@ -1012,4 +1016,36 @@ class DefaultUserWithMessage < TestModel | |
end | ||
end | ||
end | ||
|
||
context 'with regexp' do | ||
it 'returns a regexp when asked' do | ||
expect(described_class.regexp).to be_a(Regexp) | ||
end | ||
|
||
it 'returns a strict regexp when asked' do | ||
expect(described_class.regexp(:mode => :strict)).to be_a(Regexp) | ||
end | ||
|
||
it 'returns a RFC regexp when asked' do | ||
expect(described_class.regexp(:mode => :rfc)).to be_a(Regexp) | ||
end | ||
|
||
it 'has different regexp for strict and loose' do | ||
expect(described_class.regexp(:mode => :strict)).not_to eq(described_class.regexp(:mode => :loose)) | ||
end | ||
|
||
it 'has different regexp for RFC and loose' do | ||
expect(described_class.regexp(:mode => :rfc)).not_to eq(described_class.regexp(:mode => :loose)) | ||
end | ||
|
||
it 'has different regexp for RFC and strict' do | ||
expect(described_class.regexp(:mode => :rfc)).not_to eq(described_class.regexp(:mode => :strict)) | ||
end | ||
end | ||
|
||
context 'with invalid `:mode`' do | ||
it 'raises an error' do | ||
expect { described_class.regexp(:mode => :invalid) }.to raise_error(EmailValidator::Error) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters