From 21fc5edb4434e5599e6ef9a2a9fbb8458eed6bee Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Fri, 22 Jan 2021 16:07:26 +0500 Subject: [PATCH] Add semantic test fixes & maybe solution for an issue --- app/models/concerns/domain/transferable.rb | 8 ++++++-- .../epp/domain/transfer/request_test.rb | 15 ++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/models/concerns/domain/transferable.rb b/app/models/concerns/domain/transferable.rb index 9de2fff83..5400e9409 100644 --- a/app/models/concerns/domain/transferable.rb +++ b/app/models/concerns/domain/transferable.rb @@ -59,7 +59,7 @@ module Concerns::Domain::Transferable copied_ids = [] domain_contacts.each do |dc| contact = Contact.find(dc.contact_id) - next if copied_ids.include?(contact.id) || contact.registrar == new_registrar + next if copied_ids.include?(uniq_contact_hash(dc)) || contact.registrar == new_registrar if registrant_id_was == contact.id # registrant was copied previously, do not copy it again oc = OpenStruct.new(id: registrant_id) @@ -72,7 +72,11 @@ module Concerns::Domain::Transferable else dc.update(contact_id: oc.id) end - copied_ids << contact.id + copied_ids << uniq_contact_hash(dc) end end + + def uniq_contact_hash(contact) + Digest::SHA1.hexdigest(contact.contact_id.to_s + contact.type) + end end diff --git a/test/integration/epp/domain/transfer/request_test.rb b/test/integration/epp/domain/transfer/request_test.rb index 4090d9c0d..e41716457 100644 --- a/test/integration/epp/domain/transfer/request_test.rb +++ b/test/integration/epp/domain/transfer/request_test.rb @@ -14,16 +14,11 @@ class EppDomainTransferRequestTest < EppTestCase def test_new_contacts_should_be_created_after_transfer_domain registrar_id = @domain.registrar.id - contacts_id_values = [] - contact_id = Contact.find_by(registrar_id: registrar_id) + new_contact = Contact.find_by(registrar_id: registrar_id) - @domain.domain_contacts[0].update!(contact_id: contact_id.id) - @domain.domain_contacts[1].update!(contact_id: contact_id.id) - - @domain.domain_contacts.each do |contact| - contacts_id_values.push(contact.contact_id) - end + @domain.domain_contacts[0].update!(contact_id: new_contact.id) + @domain.domain_contacts[1].update!(contact_id: new_contact.id) post epp_transfer_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_goodnames' } @@ -31,7 +26,9 @@ class EppDomainTransferRequestTest < EppTestCase @domain.reload assert_epp_response :completed_successfully - assert_equal @domain.domain_contacts[0].contact_id, @domain.domain_contacts[1].contact_id + + result_hash = @domain.contacts.pluck(:original_id).group_by(&:itself).transform_values(&:count) + assert_equal result_hash[new_contact.id], 2 end def test_transfers_domain_at_once