mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
Refactor to nameserver
This commit is contained in:
parent
bc7c5d648b
commit
4ea7a7ad57
3 changed files with 19 additions and 10 deletions
|
@ -37,8 +37,6 @@ class Domain < ActiveRecord::Base
|
|||
delegate :phone, to: :owner_contact, prefix: true
|
||||
delegate :name, to: :registrar, prefix: true
|
||||
|
||||
before_validation :downcase_attributes
|
||||
|
||||
before_create :generate_auth_info
|
||||
before_create :set_validity_dates
|
||||
after_create :attach_default_contacts
|
||||
|
@ -72,14 +70,6 @@ class Domain < ActiveRecord::Base
|
|||
self[:name_dirty] = value
|
||||
end
|
||||
|
||||
def downcase_attributes
|
||||
nameservers.each do |x|
|
||||
x.hostname = x.hostname.try(:strip).try(:downcase)
|
||||
x.ipv4 = x.ipv4.try(:strip)
|
||||
x.ipv6 = x.ipv6.try(:strip).try(:upcase)
|
||||
end
|
||||
end
|
||||
|
||||
def owner_contact_typeahead
|
||||
@owner_contact_typeahead || owner_contact.try(:name) || nil
|
||||
end
|
||||
|
|
|
@ -13,6 +13,8 @@ class Nameserver < ActiveRecord::Base
|
|||
# archiving
|
||||
has_paper_trail class_name: 'NameserverVersion'
|
||||
|
||||
before_validation :normalize_attributes
|
||||
|
||||
def epp_code_map
|
||||
{
|
||||
'2302' => [
|
||||
|
@ -29,6 +31,12 @@ class Nameserver < ActiveRecord::Base
|
|||
}
|
||||
end
|
||||
|
||||
def normalize_attributes
|
||||
self.hostname = hostname.try(:strip).try(:downcase)
|
||||
self.ipv4 = ipv4.try(:strip)
|
||||
self.ipv6 = ipv6.try(:strip).try(:upcase)
|
||||
end
|
||||
|
||||
def to_s
|
||||
hostname
|
||||
end
|
||||
|
|
|
@ -69,6 +69,17 @@ describe Domain do
|
|||
expect(d.name_dirty).to eq('test.ee')
|
||||
end
|
||||
|
||||
it 'normalizes ns attrs' do
|
||||
d = Fabricate(:domain)
|
||||
d.nameservers.build(hostname: 'BLA.EXAMPLE.EE', ipv4: ' 192.168.1.1', ipv6: '1080:0:0:0:8:800:200c:417a')
|
||||
d.save
|
||||
|
||||
ns = d.nameservers.last
|
||||
expect(ns.hostname).to eq('bla.example.ee')
|
||||
expect(ns.ipv4).to eq('192.168.1.1')
|
||||
expect(ns.ipv6).to eq('1080:0:0:0:8:800:200C:417A')
|
||||
end
|
||||
|
||||
it 'does not create a reserved domain' do
|
||||
Fabricate(:reserved_domain)
|
||||
expect(Fabricate.build(:domain, name: '1162.ee').valid?).to be false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue