valid_email 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yaml +44 -0
- data/.rspec +0 -0
- data/README.md +1 -1
- data/lib/valid_email/email_validator.rb +1 -1
- data/lib/valid_email/version.rb +1 -1
- data/spec/email_validator_spec.rb +44 -18
- data/spec/spec_helper.rb +4 -1
- data/valid_email.gemspec +3 -3
- metadata +12 -11
- data/.travis.yml +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '07881400a61a403d6c3e518404847d050d28e5b28e1442205cd36daf77f5ca1d'
|
4
|
+
data.tar.gz: 9aeb926a06b6a3ca32147ae9c2c01b7aee0c5c8932668f980ca9ab2a2c4c3519
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f6cf4d94d6ecf345189b7ffc41f185977d2b23b21c011b98cfa01f5da7c1c9add6f00425b317547d14cd4dd5e4ca595b6e13523e25ceaf9163b04567b781707
|
7
|
+
data.tar.gz: 8aa4b92513c11e81b87b793a348d9581f6d11a70300006a3c1d6434032cf52b3aeacdf61b470db06ff74433ad677903156cc3967c6db7f833c9cb3bfe0c43c76
|
@@ -0,0 +1,44 @@
|
|
1
|
+
name: CI
|
2
|
+
on:
|
3
|
+
workflow_dispatch:
|
4
|
+
push:
|
5
|
+
|
6
|
+
permissions:
|
7
|
+
checks: write
|
8
|
+
contents: read
|
9
|
+
pull-requests: write
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
rspec:
|
13
|
+
name: RSpec (ruby ${{ matrix.ruby-version }})
|
14
|
+
runs-on: ubuntu-20.04
|
15
|
+
strategy:
|
16
|
+
fail-fast: false
|
17
|
+
matrix:
|
18
|
+
ruby-version:
|
19
|
+
- '1.9.3'
|
20
|
+
- '2.0'
|
21
|
+
- '2.1'
|
22
|
+
- '2.2'
|
23
|
+
- '2.3'
|
24
|
+
- '2.4'
|
25
|
+
- '2.5'
|
26
|
+
- '2.6'
|
27
|
+
- '2.7'
|
28
|
+
- '3.0'
|
29
|
+
- '3.1'
|
30
|
+
- '3.2'
|
31
|
+
- 'jruby-head'
|
32
|
+
- 'truffleruby-head'
|
33
|
+
env:
|
34
|
+
CI: true
|
35
|
+
steps:
|
36
|
+
- name: Checkout
|
37
|
+
uses: actions/checkout@v3
|
38
|
+
- name: Setup ruby
|
39
|
+
uses: ruby/setup-ruby@v1
|
40
|
+
with:
|
41
|
+
ruby-version: ${{ matrix.ruby-version }}
|
42
|
+
bundler-cache: true
|
43
|
+
- name: Run tests
|
44
|
+
run: bundle exec rake
|
data/.rspec
ADDED
File without changes
|
data/README.md
CHANGED
@@ -122,7 +122,7 @@ nil.email? # => false
|
|
122
122
|
|
123
123
|
## Code Status
|
124
124
|
|
125
|
-
[![Build Status](https://
|
125
|
+
[![Build Status](https://github.com/hallelujah/valid_email/actions/workflows/ci.yaml/badge.svg)](https://github.com/hallelujah/valid_email/actions/workflows/ci.yaml)
|
126
126
|
|
127
127
|
## Credits
|
128
128
|
|
@@ -22,7 +22,7 @@ class EmailValidator < ActiveModel::EachValidator
|
|
22
22
|
end
|
23
23
|
unless r
|
24
24
|
msg = (options[:message] || I18n.t(:invalid, :scope => "valid_email.validations.email"))
|
25
|
-
record.errors.add attribute, message: (msg
|
25
|
+
record.errors.add attribute, message: I18n.interpolate(msg, value: value)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/lib/valid_email/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ValidEmailVersion = "0.
|
1
|
+
ValidEmailVersion = "0.2.0"
|
@@ -1,5 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
RSpec::Matchers.define :have_error_messages do |field, expected|
|
4
|
+
match do |model|
|
5
|
+
errors = model.errors[field]
|
6
|
+
|
7
|
+
messages = errors.map do |error|
|
8
|
+
case error
|
9
|
+
when String then error
|
10
|
+
when Hash then error[:message]
|
11
|
+
else fail ArgumentError, "Unknown model error type #{error.class}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
expect(messages).to eq expected
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
3
19
|
describe EmailValidator do
|
4
20
|
email_class = Class.new do
|
5
21
|
include ActiveModel::Validations
|
@@ -69,43 +85,43 @@ describe EmailValidator do
|
|
69
85
|
|
70
86
|
it "fails when email empty" do
|
71
87
|
expect(subject.valid?).to be_falsey
|
72
|
-
expect(subject
|
88
|
+
expect(subject).to have_error_messages(:email, errors)
|
73
89
|
end
|
74
90
|
|
75
91
|
it "fails when email is not valid" do
|
76
92
|
subject.email = 'joh@doe'
|
77
93
|
expect(subject.valid?).to be_falsey
|
78
|
-
expect(subject
|
94
|
+
expect(subject).to have_error_messages(:email, errors)
|
79
95
|
end
|
80
96
|
|
81
97
|
it "fails when email domain is prefixed with dot" do
|
82
98
|
subject.email = 'john@.doe'
|
83
99
|
expect(subject.valid?).to be_falsey
|
84
|
-
expect(subject
|
100
|
+
expect(subject).to have_error_messages(:email, errors)
|
85
101
|
end
|
86
102
|
|
87
103
|
it "fails when email domain contains two consecutive dots" do
|
88
104
|
subject.email = 'john@doe-two..com'
|
89
105
|
expect(subject.valid?).to be_falsey
|
90
|
-
expect(subject
|
106
|
+
expect(subject).to have_error_messages(:email, errors)
|
91
107
|
end
|
92
108
|
|
93
109
|
it "fails when email ends with a period" do
|
94
110
|
subject.email = 'john@doe.com.'
|
95
111
|
expect(subject.valid?).to be_falsey
|
96
|
-
expect(subject
|
112
|
+
expect(subject).to have_error_messages(:email, errors)
|
97
113
|
end
|
98
114
|
|
99
115
|
it "fails when email ends with special characters" do
|
100
116
|
subject.email = 'john@doe.com&'
|
101
117
|
expect(subject.valid?).to be_falsey
|
102
|
-
expect(subject
|
118
|
+
expect(subject).to have_error_messages(:email, errors)
|
103
119
|
end
|
104
120
|
|
105
121
|
it "fails when email is valid with information" do
|
106
122
|
subject.email = '"John Doe" <john@doe.com>'
|
107
123
|
expect(subject.valid?).to be_falsey
|
108
|
-
expect(subject
|
124
|
+
expect(subject).to have_error_messages(:email, errors)
|
109
125
|
end
|
110
126
|
|
111
127
|
it "passes when email is simple email address" do
|
@@ -117,42 +133,52 @@ describe EmailValidator do
|
|
117
133
|
it "fails when email is simple email address not stripped" do
|
118
134
|
subject.email = 'john@doe.com '
|
119
135
|
expect(subject.valid?).to be_falsey
|
120
|
-
expect(subject
|
136
|
+
expect(subject).to have_error_messages(:email, errors)
|
121
137
|
end
|
122
138
|
|
123
139
|
it "fails when domain contains a space" do
|
124
140
|
subject.email = 'john@doe .com'
|
125
141
|
expect(subject.valid?).to be_falsey
|
126
|
-
expect(subject
|
142
|
+
expect(subject).to have_error_messages(:email, errors)
|
127
143
|
end
|
128
144
|
|
129
145
|
it "fails when passing multiple simple email addresses" do
|
130
146
|
subject.email = 'john@doe.com, maria@doe.com'
|
131
147
|
expect(subject.valid?).to be_falsey
|
132
|
-
expect(subject
|
148
|
+
expect(subject).to have_error_messages(:email, errors)
|
133
149
|
end
|
134
150
|
|
135
151
|
end
|
136
152
|
|
137
153
|
describe "validating email with MX and fallback to A" do
|
154
|
+
let(:dns) { instance_double('Resolv::DNS', :dns) }
|
155
|
+
|
138
156
|
subject { person_class_mx_with_fallback.new }
|
139
157
|
|
158
|
+
before do
|
159
|
+
allow(Resolv::DNS).to receive(:open).and_yield(dns)
|
160
|
+
end
|
161
|
+
|
140
162
|
it "passes when email domain has MX record" do
|
141
|
-
|
163
|
+
allow(dns).to receive(:getresources).with('has-mx-record.org', Resolv::DNS::Resource::IN::MX).and_return(['1.2.3.4'])
|
164
|
+
subject.email = 'john@has-mx-record.org'
|
142
165
|
expect(subject.valid?).to be_truthy
|
143
166
|
expect(subject.errors[:email]).to be_empty
|
144
167
|
end
|
145
168
|
|
146
169
|
it "passes when email domain has no MX record but has an A record" do
|
147
|
-
|
170
|
+
allow(dns).to receive(:getresources).with('has-a-record.org', Resolv::DNS::Resource::IN::MX).and_return([])
|
171
|
+
allow(dns).to receive(:getresources).with('has-a-record.org', Resolv::DNS::Resource::IN::A).and_return(['1.2.3.4'])
|
172
|
+
subject.email = 'john@has-a-record.org'
|
148
173
|
expect(subject.valid?).to be_truthy
|
149
174
|
expect(subject.errors[:email]).to be_empty
|
150
175
|
end
|
151
176
|
|
152
177
|
it "fails when domain does not exists" do
|
153
|
-
|
178
|
+
allow(dns).to receive(:getresources).with('does-not-exist.org', anything).and_return([])
|
179
|
+
subject.email = 'john@does-not-exist.org'
|
154
180
|
expect(subject.valid?).to be_falsey
|
155
|
-
expect(subject
|
181
|
+
expect(subject).to have_error_messages(:email, errors)
|
156
182
|
end
|
157
183
|
end
|
158
184
|
|
@@ -168,13 +194,13 @@ describe EmailValidator do
|
|
168
194
|
it "fails when email domain has no MX record" do
|
169
195
|
subject.email = 'john@subdomain.rubyonrails.org'
|
170
196
|
expect(subject.valid?).to be_falsey
|
171
|
-
expect(subject
|
197
|
+
expect(subject).to have_error_messages(:email, errors)
|
172
198
|
end
|
173
199
|
|
174
200
|
it "fails when domain does not exists" do
|
175
201
|
subject.email = 'john@nonexistentdomain.abc'
|
176
202
|
expect(subject.valid?).to be_falsey
|
177
|
-
expect(subject
|
203
|
+
expect(subject).to have_error_messages(:email, errors)
|
178
204
|
end
|
179
205
|
end
|
180
206
|
|
@@ -218,7 +244,7 @@ describe EmailValidator do
|
|
218
244
|
it "fails when email from disposable email services" do
|
219
245
|
subject.email = 'john@grr.la'
|
220
246
|
expect(subject.valid?).to be_falsey
|
221
|
-
expect(subject
|
247
|
+
expect(subject).to have_error_messages(:email, errors)
|
222
248
|
end
|
223
249
|
end
|
224
250
|
|
@@ -228,7 +254,7 @@ describe EmailValidator do
|
|
228
254
|
it "does not pass with an invalid domain" do
|
229
255
|
subject.email = "test@example.org$\'"
|
230
256
|
expect(subject.valid?).to be_falsey
|
231
|
-
expect(subject
|
257
|
+
expect(subject).to have_error_messages(:email, errors)
|
232
258
|
end
|
233
259
|
|
234
260
|
it "passes with valid domain" do
|
data/spec/spec_helper.rb
CHANGED
data/valid_email.gemspec
CHANGED
@@ -19,13 +19,13 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
# specify any dependencies here; for example:
|
21
21
|
s.add_development_dependency "rspec", "~> 3.10"
|
22
|
-
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "rake"
|
23
23
|
s.add_runtime_dependency "mail", ">= 2.6.1"
|
24
24
|
s.add_runtime_dependency "simpleidn"
|
25
|
-
if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('2.0')
|
25
|
+
if Gem::Version.new(RUBY_VERSION.dup) <= Gem::Version.new('2.0')
|
26
26
|
s.add_runtime_dependency 'mime-types', '<= 2.6.2'
|
27
27
|
end
|
28
|
-
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2')
|
28
|
+
if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.2.2')
|
29
29
|
s.add_runtime_dependency "activemodel", '< 5.0.0'
|
30
30
|
else
|
31
31
|
s.add_runtime_dependency "activemodel"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valid_email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ramihajamalala Hery
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mail
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,8 +87,9 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
+
- ".github/workflows/ci.yaml"
|
90
91
|
- ".gitignore"
|
91
|
-
- ".
|
92
|
+
- ".rspec"
|
92
93
|
- Gemfile
|
93
94
|
- History.md
|
94
95
|
- LICENSE
|
@@ -129,7 +130,7 @@ homepage: https://github.com/hallelujah/valid_email
|
|
129
130
|
licenses:
|
130
131
|
- MIT
|
131
132
|
metadata: {}
|
132
|
-
post_install_message:
|
133
|
+
post_install_message:
|
133
134
|
rdoc_options: []
|
134
135
|
require_paths:
|
135
136
|
- lib
|
@@ -144,8 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
145
|
- !ruby/object:Gem::Version
|
145
146
|
version: '0'
|
146
147
|
requirements: []
|
147
|
-
rubygems_version: 3.
|
148
|
-
signing_key:
|
148
|
+
rubygems_version: 3.4.13
|
149
|
+
signing_key:
|
149
150
|
specification_version: 4
|
150
151
|
summary: ActiveModel Validation for email
|
151
152
|
test_files:
|