Add test domains whitelist & fix tests

This commit is contained in:
Alex Sherman 2020-06-03 17:07:19 +05:00
parent 2d89e8124f
commit ba4e256662
3 changed files with 8 additions and 2 deletions

View file

@ -15,8 +15,9 @@ gem 'paper_trail', '~> 10.3'
gem 'pg', '1.2.2'
# 1.8 is for Rails < 5.0
gem 'ransack', '~> 2.3'
gem 'validates_email_format_of', '1.6.3' # validates email against RFC 2822 and RFC 3696
gem 'truemail', '~> 1.7' # validates email by regexp, mail server existence and address existence
gem 'validates_email_format_of', '1.6.3' # validates email against RFC 2822 and RFC 3696
# 0.7.3 is the latest for Rails 4.2, however, it is absent on Rubygems server
# https://github.com/huacnlee/rails-settings-cached/issues/165

View file

@ -88,7 +88,7 @@ class Nameserver < ApplicationRecord
end
def normalize_attributes
self.hostname = hostname.try(:strip).try(:downcase)
self.hostname = hostname.try(:strip).try(:downcase).gsub(/\.$/, '')
self.ipv4 = Array(ipv4).reject(&:blank?).map(&:strip)
self.ipv6 = Array(ipv6).reject(&:blank?).map(&:strip).map(&:upcase)
end

View file

@ -43,6 +43,11 @@ Truemail.configure do |config|
# It is equal to empty array by default.
# config.whitelisted_domains = []
unless Rails.env.production?
config.whitelisted_domains = %w[bestnames.test goodnames.test example.com inbox.test mail.test
outlook.test invalid.test email.test]
end
# Optional parameter. With this option Truemail will validate email which contains whitelisted
# domain only, i.e. if domain whitelisted, validation will passed to Regex, MX or SMTP validators.
# Validation of email which not contains whitelisted domain always will return false.