valid_email 0.0.4 → 0.0.5

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0837471ae7d6496eb96b6270bda8a0244dca52c1
4
+ data.tar.gz: 75c8181d2ec9d649306ea8c1a4d914192fab196b
5
+ SHA512:
6
+ metadata.gz: bd6495a472174bdc871f7a42d867693a8c55e5986f8d65d3669fa4df8f6f2ad78bbcea6549dfb47e753461114eb215482e33c5fed29e2c3a5d974aea26169ac9
7
+ data.tar.gz: bf8813115c60c09de4c7fbd2d0d6bfacdce156ee564f3d6aaa16c50afd48f718a90a2739b5459a37aaf03762e3dea9a2253d596eaa6b19c586f134e47bb830d8
data/README.md CHANGED
@@ -37,8 +37,14 @@ You can check if email domain has MX record :
37
37
  validates :email, :email => {:mx => true, :message => I18n.t('validations.errors.models.user.invalid_email')}
38
38
 
39
39
  Or
40
+
40
41
  validates :email, :email => {:message => I18n.t('validations.errors.models.user.invalid_email')}, :mx => {:message => I18n.t('validations.errors.models.user.invalid_mx')}
41
42
 
43
+ Alternatively, you can check if an email domain has a MX or A record by using `:mx_with_fallback` instead of `:mx`.
44
+
45
+ You can detect disposable accounts
46
+
47
+ validates :email, :email => {:ban_disposable_email => true, :message => I18n.t('validations.errors.models.user.invalid_email')}
42
48
 
43
49
  If you don't want the MX validator stuff, just require the right file
44
50
 
@@ -52,6 +58,12 @@ Or in your Gemfile
52
58
  # Credits
53
59
 
54
60
  * Dush dusanek[at]iquest.cz
61
+ * Ramihajamalala Hery hery[at]rails-royce.org
62
+ * Marco Perrando mperrando[at]soluzioninrete.it
63
+ * MIke Carter mike[at]mcarter.me
64
+ * Oleg Shur workshur[at]gmail.com
65
+ * Jörg Thalheim joerg[at]higgsboson.tk
66
+ * Jean Boussier jean.boussier[at]gmail.com
55
67
 
56
68
  # Note on Patches/Pull Requests
57
69
 
@@ -0,0 +1,5 @@
1
+ de:
2
+ valid_email:
3
+ validations:
4
+ email:
5
+ invalid: "ist ungültig"
@@ -0,0 +1,517 @@
1
+ disposable_email_services:
2
+ - mailinator.com
3
+ - devnullmail.com
4
+ - daddymail.biz
5
+ - grr.la
6
+ - drdrb.net
7
+ - getairmail.com
8
+ - evopo.com
9
+ - 6paq.com
10
+ - paplease.com
11
+ - acentri.com
12
+ - droplar.com
13
+ - appixie.com
14
+ - 0-mail.com
15
+ - 0815.ru
16
+ - 0clickemail.com
17
+ - 0wnd.net
18
+ - 0wnd.org
19
+ - 10minutemail.com
20
+ - 20minutemail.com
21
+ - 2prong.com
22
+ - 30minutemail.com
23
+ - 33mail.com
24
+ - 3d-painting.com
25
+ - 4warding.com
26
+ - 4warding.net
27
+ - 4warding.org
28
+ - 60minutemail.com
29
+ - 675hosting.com
30
+ - 675hosting.net
31
+ - 675hosting.org
32
+ - 6url.com
33
+ - 75hosting.com
34
+ - 75hosting.net
35
+ - 75hosting.org
36
+ - 7tags.com
37
+ - 9ox.net
38
+ - disposableemailaddresses.com
39
+ - putthisinyourspamdatabase.com
40
+ - sendspamhere.com
41
+ - spamherelots.com
42
+ - spamhereplease.com
43
+ - tempemail.net
44
+ - a-bc.net
45
+ - afrobacon.com
46
+ - ajaxapp.net
47
+ - amilegit.com
48
+ - amiri.net
49
+ - amiriindustries.com
50
+ - anonbox.net
51
+ - anonymbox.com
52
+ - antichef.com
53
+ - antichef.net
54
+ - antispam.de
55
+ - armyspy.com
56
+ - azmeil.tk
57
+ - baxomale.ht.cx
58
+ - beefmilk.com
59
+ - binkmail.com
60
+ - bio-muesli.net
61
+ - bobmail.info
62
+ - bodhi.lawlita.com
63
+ - bofthew.com
64
+ - boun.cr
65
+ - bouncr.com
66
+ - brefmail.com
67
+ - broadbandninja.com
68
+ - bsnow.net
69
+ - bugmenot.com
70
+ - bumpymail.com
71
+ - casualdx.com
72
+ - centermail.com
73
+ - centermail.net
74
+ - chogmail.com
75
+ - choicemail1.com
76
+ - cool.fr.nf
77
+ - correo.blogos.net
78
+ - cosmorph.com
79
+ - courriel.fr.nf
80
+ - courrieltemporaire.com
81
+ - cubiclink.com
82
+ - curryworld.de
83
+ - cust.in
84
+ - cuvox.de
85
+ - dacoolest.com
86
+ - dandikmail.com
87
+ - dayrep.com
88
+ - deadaddress.com
89
+ - deadspam.com
90
+ - despam.it
91
+ - despammed.com
92
+ - devnullmail.com
93
+ - dfgh.net
94
+ - digitalsanctuary.com
95
+ - discardmail.com
96
+ - discardmail.de
97
+ - disposableaddress.com
98
+ - disposeamail.com
99
+ - disposemail.com
100
+ - dispostable.com
101
+ - dm.w3internet.co.ukexample.com
102
+ - dodgeit.com
103
+ - dodgit.com
104
+ - dodgit.org
105
+ - donemail.ru
106
+ - dontreg.com
107
+ - dontsendmespam.de
108
+ - drdrb.com
109
+ - dump-email.info
110
+ - dumpandjunk.com
111
+ - dumpmail.de
112
+ - dumpyemail.com
113
+ - e4ward.com
114
+ - einrot.com
115
+ - email60.com
116
+ - emaildienst.de
117
+ - emailias.com
118
+ - emailigo.de
119
+ - emailinfive.com
120
+ - emailmiser.com
121
+ - emailsensei.com
122
+ - emailtemporario.com.br
123
+ - emailto.de
124
+ - emailwarden.com
125
+ - emailx.at.hm
126
+ - emailxfer.com
127
+ - emeil.in
128
+ - emeil.ir
129
+ - emz.net
130
+ - enterto.com
131
+ - ephemail.net
132
+ - etranquil.com
133
+ - etranquil.net
134
+ - etranquil.org
135
+ - explodemail.com
136
+ - fakeinbox.com
137
+ - fakeinformation.com
138
+ - fastacura.com
139
+ - fastchevy.com
140
+ - fastchrysler.com
141
+ - fastkawasaki.com
142
+ - fastmazda.com
143
+ - fastmitsubishi.com
144
+ - fastnissan.com
145
+ - fastsubaru.com
146
+ - fastsuzuki.com
147
+ - fasttoyota.com
148
+ - fastyamaha.com
149
+ - filzmail.com
150
+ - fizmail.com
151
+ - fleckens.hu
152
+ - fr33mail.info
153
+ - frapmail.com
154
+ - front14.org
155
+ - fux0ringduh.com
156
+ - garliclife.com
157
+ - get1mail.com
158
+ - get2mail.fr
159
+ - getairmail.com
160
+ - getonemail.com
161
+ - getonemail.net
162
+ - ghosttexter.de
163
+ - girlsundertheinfluence.com
164
+ - gishpuppy.com
165
+ - gowikibooks.com
166
+ - gowikicampus.com
167
+ - gowikicars.com
168
+ - gowikifilms.com
169
+ - gowikigames.com
170
+ - gowikimusic.com
171
+ - gowikinetwork.com
172
+ - gowikitravel.com
173
+ - gowikitv.com
174
+ - great-host.in
175
+ - greensloth.com
176
+ - gsrv.co.uk
177
+ - guerillamail.biz
178
+ - guerillamail.com
179
+ - guerillamail.net
180
+ - guerillamail.org
181
+ - guerrillamail.biz
182
+ - guerrillamail.com
183
+ - guerrillamail.de
184
+ - guerrillamail.net
185
+ - guerrillamail.org
186
+ - guerrillamailblock.com
187
+ - gustr.com
188
+ - h.mintemail.com
189
+ - h8s.org
190
+ - haltospam.com
191
+ - hatespam.org
192
+ - hidemail.de
193
+ - hochsitze.com
194
+ - hotpop.com
195
+ - hulapla.de
196
+ - ieatspam.eu
197
+ - ieatspam.info
198
+ - ihateyoualot.info
199
+ - iheartspam.org
200
+ - imails.info
201
+ - inbax.tk
202
+ - inboxalias.com
203
+ - inboxclean.com
204
+ - inboxclean.org
205
+ - incognitomail.com
206
+ - incognitomail.net
207
+ - incognitomail.org
208
+ - insorg-mail.info
209
+ - ipoo.org
210
+ - irish2me.com
211
+ - iwi.net
212
+ - jetable.com
213
+ - jetable.fr.nf
214
+ - jetable.net
215
+ - jetable.org
216
+ - jnxjn.com
217
+ - jourrapide.com
218
+ - junk1e.com
219
+ - kasmail.com
220
+ - kaspop.com
221
+ - keepmymail.com
222
+ - killmail.com
223
+ - killmail.net
224
+ - kir.ch.tc
225
+ - klassmaster.com
226
+ - klassmaster.net
227
+ - klzlk.com
228
+ - koszmail.pl
229
+ - kulturbetrieb.info
230
+ - kurzepost.de
231
+ - letthemeatspam.com
232
+ - lhsdv.com
233
+ - lifebyfood.com
234
+ - link2mail.net
235
+ - litedrop.com
236
+ - lol.ovpn.to
237
+ - lookugly.com
238
+ - lopl.co.cc
239
+ - lortemail.dk
240
+ - lr78.com
241
+ - m4ilweb.info
242
+ - maboard.com
243
+ - mail-temporaire.fr
244
+ - mail.by
245
+ - mail.mezimages.net
246
+ - mail2rss.org
247
+ - mail333.com
248
+ - mail4trash.com
249
+ - mailbidon.com
250
+ - mailblocks.com
251
+ - mailcatch.com
252
+ - maildrop.cc
253
+ - maileater.com
254
+ - mailexpire.com
255
+ - mailfa.tk
256
+ - mailfreeonline.com
257
+ - mailin8r.com
258
+ - mailinater.com
259
+ - mailinator.com
260
+ - mailinator.net
261
+ - mailinator2.com
262
+ - mailincubator.com
263
+ - mailme.ir
264
+ - mailme.lv
265
+ - mailmetrash.com
266
+ - mailmoat.com
267
+ - mailnator.com
268
+ - mailnesia.com
269
+ - mailnull.com
270
+ - mailshell.com
271
+ - mailsiphon.com
272
+ - mailslite.com
273
+ - mailzilla.com
274
+ - mailzilla.org
275
+ - mbx.cc
276
+ - mega.zik.dj
277
+ - meinspamschutz.de
278
+ - meltmail.com
279
+ - messagebeamer.de
280
+ - mierdamail.com
281
+ - mintemail.com
282
+ - moburl.com
283
+ - moncourrier.fr.nf
284
+ - monemail.fr.nf
285
+ - monmail.fr.nf
286
+ - msa.minsmail.com
287
+ - mt2009.com
288
+ - mx0.wwwnew.eu
289
+ - mycleaninbox.net
290
+ - mypartyclip.de
291
+ - myphantomemail.com
292
+ - myspaceinc.com
293
+ - myspaceinc.net
294
+ - myspaceinc.org
295
+ - myspacepimpedup.com
296
+ - myspamless.com
297
+ - mytrashmail.com
298
+ - neomailbox.com
299
+ - nepwk.com
300
+ - nervmich.net
301
+ - nervtmich.net
302
+ - netmails.com
303
+ - netmails.net
304
+ - netzidiot.de
305
+ - neverbox.com
306
+ - no-spam.ws
307
+ - nobulk.com
308
+ - noclickemail.com
309
+ - nogmailspam.info
310
+ - nomail.xl.cx
311
+ - nomail2me.com
312
+ - nomorespamemails.com
313
+ - nospam.ze.tc
314
+ - nospam4.us
315
+ - nospamfor.us
316
+ - nospamthanks.info
317
+ - notmailinator.com
318
+ - nowmymail.com
319
+ - nurfuerspam.de
320
+ - nus.edu.sg
321
+ - nwldx.com
322
+ - objectmail.com
323
+ - obobbo.com
324
+ - oneoffemail.com
325
+ - onewaymail.com
326
+ - online.ms
327
+ - oopi.org
328
+ - ordinaryamerican.net
329
+ - otherinbox.com
330
+ - ourklips.com
331
+ - outlawspam.com
332
+ - ovpn.to
333
+ - owlpic.com
334
+ - pancakemail.com
335
+ - pimpedupmyspace.com
336
+ - pjjkp.com
337
+ - politikerclub.de
338
+ - poofy.org
339
+ - pookmail.com
340
+ - privacy.net
341
+ - proxymail.eu
342
+ - prtnx.com
343
+ - punkass.com
344
+ - qq.com
345
+ - quickinbox.com
346
+ - rcpt.at
347
+ - recode.me
348
+ - recursor.net
349
+ - regbypass.com
350
+ - regbypass.comsafe-mail.net
351
+ - rejectmail.com
352
+ - rhyta.com
353
+ - rklips.com
354
+ - rmqkr.net
355
+ - rppkn.com
356
+ - rtrtr.com
357
+ - s0ny.net
358
+ - safe-mail.net
359
+ - safersignup.de
360
+ - safetymail.info
361
+ - safetypost.de
362
+ - sandelf.de
363
+ - saynotospams.com
364
+ - selfdestructingmail.com
365
+ - sharklasers.com
366
+ - shiftmail.com
367
+ - shitmail.me
368
+ - shortmail.net
369
+ - sibmail.com
370
+ - skeefmail.com
371
+ - slaskpost.se
372
+ - slopsbox.com
373
+ - smellfear.com
374
+ - snakemail.com
375
+ - sneakemail.com
376
+ - sofimail.com
377
+ - sofort-mail.de
378
+ - sogetthis.com
379
+ - soodonims.com
380
+ - spam.la
381
+ - spam.su
382
+ - spam4.me
383
+ - spamavert.com
384
+ - spambob.com
385
+ - spambob.net
386
+ - spambob.org
387
+ - spambog.com
388
+ - spambog.de
389
+ - spambog.ru
390
+ - spambox.info
391
+ - spambox.irishspringrealty.com
392
+ - spambox.us
393
+ - spamcannon.com
394
+ - spamcannon.net
395
+ - spamcero.com
396
+ - spamcon.org
397
+ - spamcorptastic.com
398
+ - spamcowboy.com
399
+ - spamcowboy.net
400
+ - spamcowboy.org
401
+ - spamday.com
402
+ - spamex.com
403
+ - spamfree24.com
404
+ - spamfree24.de
405
+ - spamfree24.eu
406
+ - spamfree24.info
407
+ - spamfree24.net
408
+ - spamfree24.org
409
+ - spamgourmet.com
410
+ - spamgourmet.net
411
+ - spamgourmet.org
412
+ - spamhole.com
413
+ - spamify.com
414
+ - spaminator.de
415
+ - spamkill.info
416
+ - spaml.com
417
+ - spaml.de
418
+ - spammotel.com
419
+ - spamobox.com
420
+ - spamoff.de
421
+ - spamslicer.com
422
+ - spamspot.com
423
+ - spamthis.co.uk
424
+ - spamthisplease.com
425
+ - spamtrail.com
426
+ - speed.1s.fr
427
+ - supergreatmail.com
428
+ - supermailer.jp
429
+ - superrito.com
430
+ - suremail.info
431
+ - tagyourself.com
432
+ - teewars.org
433
+ - teleworm.com
434
+ - teleworm.us
435
+ - tempalias.com
436
+ - tempe-mail.com
437
+ - tempemail.biz
438
+ - tempemail.com
439
+ - tempinbox.co.uk
440
+ - tempinbox.com
441
+ - tempmail.it
442
+ - tempmail2.com
443
+ - tempomail.fr
444
+ - temporarily.de
445
+ - temporarioemail.com.br
446
+ - temporaryemail.net
447
+ - temporaryforwarding.com
448
+ - temporaryinbox.com
449
+ - thanksnospam.info
450
+ - thankyou2010.com
451
+ - thisisnotmyrealemail.com
452
+ - throwawayemailaddress.com
453
+ - tilien.com
454
+ - tmailinator.com
455
+ - tradermail.info
456
+ - trash-amil.com
457
+ - trash-mail.at
458
+ - trash-mail.com
459
+ - trash-mail.de
460
+ - trash2009.com
461
+ - trashemail.de
462
+ - trashmail.at
463
+ - trashmail.com
464
+ - trashmail.de
465
+ - trashmail.me
466
+ - trashmail.net
467
+ - trashmail.org
468
+ - trashmail.ws
469
+ - trashmailer.com
470
+ - trashymail.com
471
+ - trashymail.net
472
+ - trillianpro.com
473
+ - turual.com
474
+ - twinmail.de
475
+ - tyldd.com
476
+ - uggsrock.com
477
+ - upliftnow.com
478
+ - uplipht.com
479
+ - venompen.com
480
+ - veryrealemail.com
481
+ - viditag.com
482
+ - viewcastmedia.com
483
+ - viewcastmedia.net
484
+ - viewcastmedia.org
485
+ - webm4il.info
486
+ - wegwerfadresse.de
487
+ - wegwerfemail.de
488
+ - wegwerfmail.de
489
+ - wegwerfmail.net
490
+ - wegwerfmail.org
491
+ - wetrainbayarea.com
492
+ - wetrainbayarea.org
493
+ - wh4f.org
494
+ - whatpaas.com
495
+ - whyspam.me
496
+ - willselfdestruct.com
497
+ - winemaven.info
498
+ - wronghead.com
499
+ - wuzup.net
500
+ - wuzupmail.net
501
+ - wwwnew.eu
502
+ - xagloo.com
503
+ - xemaps.com
504
+ - xents.com
505
+ - xmaily.com
506
+ - xoxy.net
507
+ - yep.it
508
+ - yogamaven.com
509
+ - yopmail.com
510
+ - yopmail.fr
511
+ - yopmail.net
512
+ - ypmail.webarnak.fr.eu.org
513
+ - yuurok.com
514
+ - zehnminutenmail.de
515
+ - zippymail.info
516
+ - zoaxe.com
517
+ - zoemail.org
@@ -1,2 +1,5 @@
1
1
  require 'valid_email/all'
2
2
  I18n.load_path += Dir.glob(File.expand_path('../../config/locales/**/*',__FILE__))
3
+ # Load list of disposable email domains
4
+ config = File.expand_path('../../config/valid_email.yml',__FILE__)
5
+ BanDisposableEmailValidator.config= YAML.load_file(config)['disposable_email_services'] rescue []
@@ -1,2 +1,4 @@
1
1
  require 'valid_email/email_validator'
2
- require 'valid_email/mx_validator'
2
+ require 'valid_email/mx_validator'
3
+ require 'valid_email/mx_with_fallback_validator'
4
+ require 'valid_email/ban_disposable_email_validator'
@@ -0,0 +1,19 @@
1
+ require 'active_model'
2
+ require 'active_model/validations'
3
+ require 'mail'
4
+ class BanDisposableEmailValidator < ActiveModel::EachValidator
5
+ # A list of disposable email domains
6
+ def self.config=(options)
7
+ @@config = options
8
+ end
9
+
10
+ def validate_each(record, attribute, value)
11
+ begin
12
+ m = Mail::Address.new(value)
13
+ r = !@@config.include?(m.domain) if m.domain
14
+ rescue Exception => e
15
+ r = false
16
+ end
17
+ record.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => "valid_email.validations.email")) unless r
18
+ end
19
+ end
@@ -4,6 +4,9 @@ require 'mail'
4
4
  class EmailValidator < ActiveModel::EachValidator
5
5
  def validate_each(record,attribute,value)
6
6
  begin
7
+ return if options[:allow_nil] && value.nil?
8
+ return if options[:allow_blank] && value.blank?
9
+
7
10
  m = Mail::Address.new(value)
8
11
  # We must check that value contains a domain and that value is an email address
9
12
  r = m.domain && m.address == value
@@ -19,6 +22,14 @@ class EmailValidator < ActiveModel::EachValidator
19
22
  if r && options[:mx]
20
23
  require 'valid_email/mx_validator'
21
24
  r &&= MxValidator.new(:attributes => attributes).validate(record)
25
+ elsif r && options[:mx_with_fallback]
26
+ require 'valid_email/mx_with_fallback_validator'
27
+ r &&= MxWithFallbackValidator.new(:attributes => attributes).validate(record)
28
+ end
29
+ # Check if domain is disposable
30
+ if r && options[:ban_disposable_email]
31
+ require 'valid_email/ban_disposable_email_validator'
32
+ r &&= BanDisposableEmailValidator.new(:attributes => attributes).validate(record)
22
33
  end
23
34
  rescue Exception => e
24
35
  r = false
@@ -4,13 +4,22 @@ require 'mail'
4
4
  require 'resolv'
5
5
  class MxValidator < ActiveModel::EachValidator
6
6
  def validate_each(record,attribute,value)
7
- m = Mail::Address.new(value)
7
+ begin
8
+ m = Mail::Address.new(value)
9
+ if m.domain
10
+ r = valid_domain?(m.domain)
11
+ end
12
+ rescue Mail::Field::ParseError
13
+ #ignore this
14
+ end
15
+ record.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => "valid_email.validations.email")) unless r
16
+ end
17
+
18
+ def valid_domain?(domain)
8
19
  mx = []
9
20
  Resolv::DNS.open do |dns|
10
- mx.concat dns.getresources(m.domain, Resolv::DNS::Resource::IN::MX)
21
+ mx.concat dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
11
22
  end
12
- r = mx.size > 0
13
- record.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => "valid_email.validations.email")) unless r
14
- r
23
+ mx.size > 0
15
24
  end
16
25
  end
@@ -0,0 +1,11 @@
1
+ require 'valid_email/mx_validator'
2
+ class MxWithFallbackValidator < MxValidator
3
+ def valid_domain?(domain)
4
+ mx = []
5
+ Resolv::DNS.open do |dns|
6
+ mx.concat dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
7
+ mx.concat dns.getresources(domain, Resolv::DNS::Resource::IN::A)
8
+ end
9
+ mx.size > 0
10
+ end
11
+ end
@@ -1,2 +1 @@
1
- ValidEmailVersion = "0.0.4"
2
-
1
+ ValidEmailVersion = "0.0.5"
@@ -13,9 +13,51 @@ describe EmailValidator do
13
13
  validates :email, :email => {:mx => true}
14
14
  end
15
15
 
16
+ person_class_mx_with_fallback = Class.new do
17
+ include ActiveModel::Validations
18
+ attr_accessor :email
19
+ validates :email, :email => {:mx_with_fallback => true}
20
+ end
21
+
22
+ person_class_disposable_email = Class.new do
23
+ include ActiveModel::Validations
24
+ attr_accessor :email
25
+ validates :email, :email => {:ban_disposable_email => true}
26
+ end
27
+
28
+ person_class_nil_allowed = Class.new do
29
+ include ActiveModel::Validations
30
+ attr_accessor :email
31
+ validates :email, :email => {:allow_nil => true}
32
+ end
33
+
34
+ person_class_blank_allowed = Class.new do
35
+ include ActiveModel::Validations
36
+ attr_accessor :email
37
+ validates :email, :email => {:allow_blank => true}
38
+ end
39
+
40
+ person_class_mx_separated = Class.new do
41
+ include ActiveModel::Validations
42
+ attr_accessor :email
43
+ validates :email, :mx => true
44
+ end
45
+
46
+ person_class_mx_with_fallback_separated = Class.new do
47
+ include ActiveModel::Validations
48
+ attr_accessor :email
49
+ validates :email, :mx_with_fallback => true
50
+ end
51
+
52
+ shared_examples_for "Invalid model" do
53
+ before { subject.valid? }
54
+
55
+ it { should_not be_valid }
56
+ specify { subject.errors[:email].should =~ errors }
57
+ end
16
58
 
17
59
  shared_examples_for "Validating emails" do
18
-
60
+
19
61
  before :each do
20
62
  I18n.locale = locale
21
63
  end
@@ -60,6 +102,28 @@ describe EmailValidator do
60
102
 
61
103
  end
62
104
 
105
+ describe "validating email with MX and fallback to A" do
106
+ subject { person_class_mx_with_fallback.new }
107
+
108
+ it "should pass when email domain has MX record" do
109
+ subject.email = 'john@gmail.com'
110
+ subject.valid?.should be_true
111
+ subject.errors[:email].should be_empty
112
+ end
113
+
114
+ it "should pass when email domain has no MX record but has an A record" do
115
+ subject.email = 'john@subdomain.rubyonrails.org'
116
+ subject.valid?.should be_true
117
+ subject.errors[:email].should be_empty
118
+ end
119
+
120
+ it "should fail when domain does not exists" do
121
+ subject.email = 'john@nonexistentdomain.abc'
122
+ subject.valid?.should be_false
123
+ subject.errors[:email].should == errors
124
+ end
125
+ end
126
+
63
127
  describe "validating email with MX" do
64
128
  subject { person_class_mx.new }
65
129
 
@@ -81,19 +145,85 @@ describe EmailValidator do
81
145
  subject.errors[:email].should == errors
82
146
  end
83
147
  end
148
+
149
+ describe "validating MX with fallback to A" do
150
+ subject { person_class_mx_with_fallback_separated.new }
151
+
152
+ context "when domain is not specified" do
153
+ before { subject.email = 'john' }
154
+ it_should_behave_like "Invalid model"
155
+ end
156
+
157
+ context "when domain is not specified but @ is" do
158
+ before { subject.email = 'john@' }
159
+ it_should_behave_like "Invalid model"
160
+ end
161
+ end
162
+
163
+ describe "validating MX" do
164
+ subject { person_class_mx_separated.new }
165
+
166
+ context "when domain is not specified" do
167
+ before { subject.email = 'john' }
168
+ it_should_behave_like "Invalid model"
169
+ end
170
+
171
+ context "when domain is not specified but @ is" do
172
+ before { subject.email = 'john@' }
173
+ it_should_behave_like "Invalid model"
174
+ end
175
+ end
176
+
177
+ describe "validating email from disposable service" do
178
+ subject { person_class_disposable_email.new }
179
+
180
+ it "should pass when email from trusted email services" do
181
+ subject.email = 'john@mail.ru'
182
+ subject.valid?.should be_true
183
+ subject.errors[:email].should be_empty
184
+ end
185
+
186
+ it "should fail when email from disposable email services" do
187
+ subject.email = 'john@grr.la'
188
+ subject.valid?.should be_false
189
+ subject.errors[:email].should == errors
190
+ end
191
+ end
192
+
193
+ end
194
+
195
+ describe "Can allow nil" do
196
+ subject { person_class_nil_allowed.new }
197
+
198
+ it "should pass even if mail isn't set" do
199
+ subject.email = nil
200
+ subject.should be_valid
201
+ subject.errors[:email].should be_empty
202
+ end
203
+
204
+ end
205
+
206
+ describe "Can allow blank" do
207
+ subject { person_class_blank_allowed.new }
208
+
209
+ it "should pass even if mail is a blank string set" do
210
+ subject.email = ''
211
+ subject.should be_valid
212
+ subject.errors[:email].should be_empty
213
+ end
214
+
84
215
  end
85
-
216
+
86
217
  describe "Translating in english" do
87
218
  let!(:locale){ :en }
88
219
  let!(:errors) { [ "is invalid" ] }
89
220
  it_should_behave_like "Validating emails"
90
221
  end
91
-
222
+
92
223
  describe "Translating in french" do
93
224
  let!(:locale){ :fr }
94
-
225
+
95
226
  let!(:errors) { [ "est invalide" ] }
96
227
  it_should_behave_like "Validating emails"
97
228
  end
98
-
99
- end
229
+ end
metadata CHANGED
@@ -1,60 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valid_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ramihajamalala Hery
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-01-23 00:00:00.000000000Z
11
+ date: 2014-05-30 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
- requirement: &13116240 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *13116240
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rake
27
- requirement: &13115440 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *13115440
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: mail
38
- requirement: &13111340 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
- - - ! '>='
45
+ - - ">="
42
46
  - !ruby/object:Gem::Version
43
47
  version: '0'
44
48
  type: :runtime
45
49
  prerelease: false
46
- version_requirements: *13111340
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: activemodel
49
- requirement: &13110020 !ruby/object:Gem::Requirement
50
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ! '>='
59
+ - - ">="
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  type: :runtime
56
63
  prerelease: false
57
- version_requirements: *13110020
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
58
69
  description: ActiveModel Validation for email
59
70
  email:
60
71
  - hery@rails-royce.org
@@ -62,51 +73,48 @@ executables: []
62
73
  extensions: []
63
74
  extra_rdoc_files: []
64
75
  files:
65
- - .gitignore
66
- - .rvmrc
76
+ - ".gitignore"
77
+ - ".rvmrc"
67
78
  - Gemfile
68
79
  - LICENSE
69
80
  - README.md
70
81
  - Rakefile
82
+ - config/locales/de.yml
71
83
  - config/locales/en.yml
72
84
  - config/locales/fr.yml
85
+ - config/valid_email.yml
73
86
  - lib/valid_email.rb
74
87
  - lib/valid_email/all.rb
88
+ - lib/valid_email/ban_disposable_email_validator.rb
75
89
  - lib/valid_email/email_validator.rb
76
90
  - lib/valid_email/mx_validator.rb
91
+ - lib/valid_email/mx_with_fallback_validator.rb
77
92
  - lib/valid_email/version.rb
78
93
  - spec/email_validator_spec.rb
79
94
  - spec/spec_helper.rb
80
95
  - valid_email.gemspec
81
96
  homepage: http://my.rails-royce.org/2010/07/21/email-validation-in-ruby-on-rails-without-regexp
82
97
  licenses: []
98
+ metadata: {}
83
99
  post_install_message:
84
100
  rdoc_options: []
85
101
  require_paths:
86
102
  - lib
87
103
  required_ruby_version: !ruby/object:Gem::Requirement
88
- none: false
89
104
  requirements:
90
- - - ! '>='
105
+ - - ">="
91
106
  - !ruby/object:Gem::Version
92
107
  version: '0'
93
- segments:
94
- - 0
95
- hash: -4220609047833708671
96
108
  required_rubygems_version: !ruby/object:Gem::Requirement
97
- none: false
98
109
  requirements:
99
- - - ! '>='
110
+ - - ">="
100
111
  - !ruby/object:Gem::Version
101
112
  version: '0'
102
- segments:
103
- - 0
104
- hash: -4220609047833708671
105
113
  requirements: []
106
114
  rubyforge_project: valid_email
107
- rubygems_version: 1.8.15
115
+ rubygems_version: 2.2.2
108
116
  signing_key:
109
- specification_version: 3
117
+ specification_version: 4
110
118
  summary: ActiveModel Validation for email
111
119
  test_files:
112
120
  - spec/email_validator_spec.rb