diff --git a/lib/valid_email2/email_validator.rb b/lib/valid_email2/email_validator.rb index a88f77f..d9fd3e5 100644 --- a/lib/valid_email2/email_validator.rb +++ b/lib/valid_email2/email_validator.rb @@ -44,7 +44,7 @@ def validate_each(record, attribute, value) end if options[:disposable_with_allow_list] - error(record, attribute, :disposable_with_allow_list) && return if addresses.any? { |address| address.disposable? && !address.allow_listed? } + error(record, attribute, :disposable_with_allow_list) && return if addresses.any? { |address| !address.allow_listed? && address.disposable? } end if options[:disposable_domain_with_allow_list] diff --git a/spec/valid_email2_spec.rb b/spec/valid_email2_spec.rb index 70cca55..eae6184 100644 --- a/spec/valid_email2_spec.rb +++ b/spec/valid_email2_spec.rb @@ -297,6 +297,14 @@ def set_allow_list expect(user.valid?).to be_truthy end + it "does not look up MX servers if the domain is in the allow list" do + File.open(allow_list_file_path, "w") { |f| f.write ["gmail.com"].to_yaml } + set_allow_list + expect_any_instance_of(ValidEmail2::Dns).not_to receive(:mx_servers) + user = TestUserDisallowDisposableWithAllowList.new(email: "foo@gmail.com") + expect(user.valid?).to be_truthy + end + it "is invalid if the domain is a disposable_domain and not in the allow list" do user = TestUserDisallowDisposableDomainWithAllowList.new(email: "foo@#{allow_list_domain}") expect(user.valid?).to be_falsey