diff --git a/app/models/domain.rb b/app/models/domain.rb
index 1f52863ed..6dd477746 100644
--- a/app/models/domain.rb
+++ b/app/models/domain.rb
@@ -61,7 +61,10 @@ class Domain < ActiveRecord::Base
end
def detach_objects(ph, parsed_frame)
+ detach_contacts(self.class.parse_contacts_from_frame(parsed_frame))
detach_nameservers(self.class.parse_nameservers_from_frame(parsed_frame))
+
+ errors.empty?
end
def attach_owner_contact(code)
@@ -120,10 +123,39 @@ class Domain < ActiveRecord::Base
end
end
+ def detach_contacts(contact_list)
+ to_delete = []
+ contact_list.each do |k, v|
+ v.each do |x|
+ contact = domain_contacts.joins(:contact).where(contacts: {code: x[:contact]})
+ if contact.blank?
+ errors.add(:domain_contacts, {
+ obj: 'contact',
+ val: x[:contact],
+ msg: errors.generate_message(:domain_contacts, :not_found)
+ })
+ else
+ to_delete << contact
+ end
+ end
+ end
+
+ self.domain_contacts.delete(to_delete)
+ end
+
def detach_nameservers(ns_list)
to_delete = []
ns_list.each do |ns_attrs|
- to_delete << self.nameservers.where(ns_attrs)
+ nameserver = self.nameservers.where(ns_attrs)
+ if nameserver.blank?
+ errors.add(:nameservers, {
+ obj: 'hostObj',
+ val: ns_attrs[:hostname],
+ msg: errors.generate_message(:nameservers, :not_found)
+ })
+ else
+ to_delete << nameserver
+ end
end
self.nameservers.delete(to_delete)
@@ -199,7 +231,8 @@ class Domain < ActiveRecord::Base
],
'2303' => [ # Object does not exist
[:owner_contact, :epp_registrant_not_found],
- [:domain_contacts, :not_found]
+ [:domain_contacts, :not_found],
+ [:nameservers, :not_found]
],
'2200' => [
[:auth_info, :wrong_pw]
diff --git a/config/locales/en.yml b/config/locales/en.yml
index eea6c7fae..f1a1f3258 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -50,6 +50,7 @@ en:
blank: 'Admin contact is missing'
nameservers:
out_of_range: 'Nameservers count must be between %{min}-%{max}'
+ not_found: 'Nameserver was not found'
period:
out_of_range: 'Period must add up to 1, 2 or 3 years'
auth_info:
diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb
index 9d2792475..64f2f0d61 100644
--- a/spec/epp/domain_spec.rb
+++ b/spec/epp/domain_spec.rb
@@ -285,13 +285,23 @@ describe 'EPP Domain', epp: true do
d = Domain.last
- new_ns = d.nameservers.find_by(hostname: 'ns1.example.com')
- expect(new_ns).to be_truthy
-
response = epp_request('domains/update_remove_objects.xml')
rem_ns = d.nameservers.find_by(hostname: 'ns1.example.com')
expect(rem_ns).to be_falsey
+
+ rem_cnt = d.tech_contacts.find_by(code: 'mak21')
+ expect(rem_cnt).to be_falsey
+
+ response = epp_request('domains/update_remove_objects.xml')
+
+ expect(response[:results][0][:result_code]).to eq('2303')
+ expect(response[:results][0][:msg]).to eq('Contact was not found')
+ expect(response[:results][0][:value]).to eq('mak21')
+
+ expect(response[:results][1][:result_code]).to eq('2303')
+ expect(response[:results][1][:msg]).to eq('Nameserver was not found')
+ expect(response[:results][1][:value]).to eq('ns1.example.com')
end
end
diff --git a/spec/epp/requests/domains/update_remove_objects.xml b/spec/epp/requests/domains/update_remove_objects.xml
index fd79586c3..9d96e4df6 100644
--- a/spec/epp/requests/domains/update_remove_objects.xml
+++ b/spec/epp/requests/domains/update_remove_objects.xml
@@ -9,7 +9,7 @@
ns1.example.com
- sh8013
+ mak21