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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 912afd4576d829541b67adb5b5830c4c31d8bf7f7005092957a655f9dbcf07ba
4
- data.tar.gz: a0647b0db0f921c5159c585fb2298211f1be85cafe138fd426ebf1ec5d32049d
3
+ metadata.gz: '07881400a61a403d6c3e518404847d050d28e5b28e1442205cd36daf77f5ca1d'
4
+ data.tar.gz: 9aeb926a06b6a3ca32147ae9c2c01b7aee0c5c8932668f980ca9ab2a2c4c3519
5
5
  SHA512:
6
- metadata.gz: bc35a4b3adb7b092b9158dff8d2d2c16bd1e5cc5f59b91f521ea0cbfd30d0bd5c4c523f2990752486036fed8db8908566228eee18b7f3c282f7b9824cca0b1f2
7
- data.tar.gz: 44233a8c92c72e597c3b10bdc052e17c1e8ead83c87dfab94103f7341d9b2b32348f555fbe4fdee2af0e474c7af92f253b3421fb4ed37aed779eabc30c1a9cbd
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://travis-ci.org/hallelujah/valid_email.svg?branch=master)](https://travis-ci.org/hallelujah/valid_email)
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 % {value: value})
25
+ record.errors.add attribute, message: I18n.interpolate(msg, value: value)
26
26
  end
27
27
  end
28
28
  end
@@ -1 +1 @@
1
- ValidEmailVersion = "0.1.4"
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.errors[:email]).to eq errors
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.errors[:email]).to eq errors
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.errors[:email]).to eq errors
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.errors[:email]).to eq errors
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.errors[:email]).to eq errors
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.errors[:email]).to eq errors
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.errors[:email]).to eq errors
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.errors[:email]).to eq errors
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.errors[:email]).to eq errors
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.errors[:email]).to eq errors
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
- subject.email = 'john@gmail.com'
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
- subject.email = 'john@subdomain.rubyonrails.org'
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
- subject.email = 'john@nonexistentdomain.abc'
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.errors[:email]).to eq errors
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.errors[:email]).to eq errors
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.errors[:email]).to eq errors
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.errors[:email]).to eq errors
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.errors[:email]).to eq errors
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
@@ -3,7 +3,10 @@ require 'valid_email'
3
3
 
4
4
  RSpec.configure do |config|
5
5
  config.order = :random
6
- config.profile_examples = 10
7
6
  config.raise_errors_for_deprecations!
8
7
  Kernel.srand config.seed
8
+
9
+ if ENV['CI']
10
+ config.warnings = true
11
+ end
9
12
  end
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", '< 11.0'
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.1.4
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: 2021-08-30 00:00:00.000000000 Z
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: '11.0'
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: '11.0'
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
- - ".travis.yml"
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.1.4
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:
data/.travis.yml DELETED
@@ -1,18 +0,0 @@
1
- before_install:
2
- - gem install bundler:1.17.3
3
- cache: bundler
4
- dist: xenial
5
- language: ruby
6
- rvm:
7
- - 1.9.3
8
- - 2.0
9
- - 2.1
10
- - 2.2
11
- - 2.2
12
- - 2.3
13
- - 2.4
14
- - 2.5
15
- - 2.6
16
- - 2.7
17
- - 3.0
18
- - jruby-head