Validate email domains

The gem checks the DNS system for a valid domain entry.
This commit is contained in:
Maikel Linke
2023-05-15 16:14:15 +10:00
committed by Konrad
parent ffc45f77cf
commit 90cbac7176
3 changed files with 14 additions and 2 deletions

View File

@@ -48,7 +48,7 @@ module Spree
after_create :associate_customers, :associate_orders
validates :email, 'valid_email_2/email': true, if: :email_changed?
validates :email, 'valid_email_2/email': { mx: true }, if: :email_changed?
validate :limit_owned_enterprises
validates :uid, uniqueness: true, if: lambda { uid.present? }
validates_email :uid, if: lambda { uid.present? }

View File

@@ -127,6 +127,15 @@ RSpec.configure do |config|
end
end
# Don't validate our invalid test data with expensive network requests.
config.before(:each) do
allow_any_instance_of(ValidEmail2::Address).to receive_messages(
valid_mx?: true,
valid_strict_mx?: true,
mx_server_is_in?: false
)
end
# Webmock raises errors that inherit directly from Exception (not StandardError).
# The messages contain useful information for debugging stubbed requests to external
# services (in tests), but they normally don't appear in the test output.

View File

@@ -102,7 +102,10 @@ describe Spree::User do
expect(user).to be_valid
end
pending "detects typos in the domain" do
it "detects typos in the domain" do
# We mock this validation in all other tests because our test data is not
# valid, the network requests slow down tests and could make them flaky.
expect_any_instance_of(ValidEmail2::Address).to receive(:valid_mx?).and_call_original
user.email = "example@ho020tmail.com"
expect(user).to_not be_valid
end