typoed_email_validator: add new ending to the typo list

also:
- consider '.mail' TLD a typo
- get rid of a deprecation warning
This commit is contained in:
Georg Gadinger 2022-03-04 06:13:38 +01:00 committed by Karina Kwiatek
parent 703ff54f5f
commit 3d6fb9dc34
2 changed files with 7 additions and 4 deletions

View file

@ -6,6 +6,7 @@ class TypoedEmailValidator < ActiveModel::EachValidator
# without @:
".con",
".coom",
".mail",
# with @:
*%w[
@ -15,15 +16,15 @@ class TypoedEmailValidator < ActiveModel::EachValidator
gmaile.com
gmaill.com
gmali.com
hotmaill.com
icluod.com
proton.mail
].map { "@#{_1}" }
].freeze
def validate_each(record, attribute, value)
return if valid?(value)
record.errors[attribute] << "contains a typo"
record.errors.add(attribute, :typo, message: "contains a typo")
end
private

View file

@ -62,6 +62,7 @@ RSpec.describe User, type: :model do
include_examples "valid email", "fritz.fantom@gmail.com"
include_examples "valid email", "fritz.fantom@columbiamail.co"
include_examples "valid email", "fritz.fantom@protonmail.com"
include_examples "valid email", "fritz.fantom@example.email"
include_examples "valid email", "fritz.fantom@enterprise.k8s.420stripes.k8s.needs.more.k8s.jira.atlassian.k8s.eu-central-1.s3.amazonaws.com"
include_examples "invalid email", "@jack"
@ -72,6 +73,8 @@ RSpec.describe User, type: :model do
include_examples "invalid email", "fritz.fantom@protonmail.con"
# neither is .coom
include_examples "invalid email", "fritz.fantom@gmail.coom"
# nor .mail (.email is, however)
include_examples "invalid email", "fritz.fantom@proton.mail"
# common typos:
include_examples "invalid email", "fritz.fantom@fmail.com"
include_examples "invalid email", "fritz.fantom@gemail.com"
@ -81,12 +84,11 @@ RSpec.describe User, type: :model do
include_examples "invalid email", "fritz.fantom@gmaill.com"
include_examples "invalid email", "fritz.fantom@gmali.com"
include_examples "invalid email", "fritz.fantom@hotmailcom"
include_examples "invalid email", "fritz.fantom@hotmaill.com"
include_examples "invalid email", "fritz.fantom@icluod.com"
# no TLD
include_examples "invalid email", "fritz.fantom@gmail"
include_examples "invalid email", "fritz.fantom@protonmail"
# not registered as of 2022-01-11
include_examples "invalid email", "fritz.fantom@proton.mail"
end
# -- User::TimelineMethods --