114677695-additional_validation_rule

This commit is contained in:
Stas 2016-05-24 16:34:26 +03:00
parent b18021774d
commit fa2231b27e

View file

@ -16,6 +16,7 @@ class Nameserver < ActiveRecord::Base
# rubocop: enable Metrics/LineLength
before_validation :normalize_attributes
before_validation :check_puny_symbols
delegate :name, to: :domain, prefix: true
@ -41,6 +42,11 @@ class Nameserver < ActiveRecord::Base
self.ipv6 = Array(ipv6).reject(&:blank?).map(&:strip).map(&:upcase)
end
def check_puny_symbols
regexp = /(\A|\.)..--/
errors.add(:hostname, :invalid) if hostname =~ regexp
end
def to_s
hostname
end