Add owner to technical and admin contact when no other contacts are specified

This commit is contained in:
Martin Lensment 2014-07-31 12:09:07 +03:00
parent 62b3ff6fc7
commit 3c3a8bfb47
3 changed files with 31 additions and 5 deletions

View file

@ -11,8 +11,9 @@ class Contact < ActiveRecord::Base
validate :ident_must_be_valid
validates :phone, format: { with: /\+\d{3}\.\d+/, message: "bad format" }
IDENT_TYPE_ICO = 'ico'
IDENT_TYPES = [
"ico", #Company registry code (or similar)
IDENT_TYPE_ICO, #Company registry code (or similar)
"op", #Estonian ID
"passport", #Passport number
"birthday" #Birthday date
@ -30,6 +31,14 @@ class Contact < ActiveRecord::Base
errors.add(:ident, 'bad format') unless code.valid?
end
def juridical?
ident == IDENT_TYPE_ICO
end
def citizen?
ident != IDENT_TYPE_ICO
end
class << self
def check_availability(codes)
codes = [codes] if codes.is_a?(String)

View file

@ -36,12 +36,23 @@ class Domain < ActiveRecord::Base
def attach_contacts(contacts)
contacts.each do |k, v|
v.each do |x|
domain_contacts.create(
contact: Contact.find_by(code: x[:contact]),
contact_type: k
)
attach_contact(k, Contact.find_by(code: x[:contact]))
end
end
if owner_contact.citizen?
attach_contact(Contact::CONTACT_TYPE_TECH, owner_contact) if tech_contacts.empty?
attach_contact(Contact::CONTACT_TYPE_ADMIN, owner_contact) if admin_contacts.empty?
end
true
end
def attach_contact(type, contact)
domain_contacts.create(
contact: contact,
contact_type: type
)
end
class << self

View file

@ -14,7 +14,13 @@ describe 'EPP Domain', epp: true do
expect(response[:result_code]).to eq('1000')
expect(response[:msg]).to eq('Command completed successfully')
expect(response[:clTRID]).to eq('ABC-12345')
expect(Domain.first.registrar.name).to eq('Zone Media OÜ')
expect(Domain.first.tech_contacts.count).to eq 1
expect(Domain.first.admin_contacts.count).to eq 1
tech_contact = Domain.first.tech_contacts.first
expect(tech_contact.code).to eq('jd1234')
end
it 'does not create duplicate domain' do