mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Validate email domains
The gem checks the DNS system for a valid domain entry.
This commit is contained in:
@@ -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? }
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user