Clone owner contact if contact has more domains

This commit is contained in:
Martin Lensment 2015-03-11 19:01:58 +02:00
parent 568121ddd0
commit 33f7920ad8
4 changed files with 16 additions and 4 deletions

View file

@ -60,6 +60,9 @@ gem 'newrelic_rpm', '~> 3.9.9.275'
# country listing # country listing
gem 'countries', '~> 0.10.0' gem 'countries', '~> 0.10.0'
# cloning activerecord objects
gem 'deep_cloneable', '~> 2.1.1'
group :development do group :development do
# dev tools # dev tools
gem 'spring', '~> 1.2.0' gem 'spring', '~> 1.2.0'

View file

@ -122,6 +122,8 @@ GEM
daemons (1.1.9) daemons (1.1.9)
database_cleaner (1.3.0) database_cleaner (1.3.0)
debug_inspector (0.0.2) debug_inspector (0.0.2)
deep_cloneable (2.1.1)
activerecord (>= 3.1.0, < 5.0.0)
delayed_job (4.0.6) delayed_job (4.0.6)
activesupport (>= 3.0, < 5.0) activesupport (>= 3.0, < 5.0)
delayed_job_active_record (4.0.3) delayed_job_active_record (4.0.3)
@ -455,6 +457,7 @@ DEPENDENCIES
countries (~> 0.10.0) countries (~> 0.10.0)
daemons (~> 1.1.9) daemons (~> 1.1.9)
database_cleaner (~> 1.3.0) database_cleaner (~> 1.3.0)
deep_cloneable (~> 2.1.1)
delayed_job_active_record (~> 4.0.3) delayed_job_active_record (~> 4.0.3)
devise (~> 3.4.1) devise (~> 3.4.1)
epp (~> 1.4.0) epp (~> 1.4.0)

View file

@ -401,8 +401,14 @@ class Epp::Domain < Domain
end end
def transfer_contacts(current_user) def transfer_contacts(current_user)
if owner_contact.domains.count > 1 if owner_contact.domains_owned.count > 1
# create new c = Contact.find(owner_contact_id)
oc = c.deep_clone include: [:statuses, :address]
oc.code = nil
oc.registrar_id = current_user.registrar_id
oc.save!
self.owner_contact_id = oc.id
else else
# transfer contact # transfer contact
# TODO: This is a workaround so Bullet won't complain about n+1 query # TODO: This is a workaround so Bullet won't complain about n+1 query

View file

@ -914,7 +914,7 @@ describe 'EPP Domain', epp: true do
end end
# all domain contacts should be under registrar2 now # all domain contacts should be under registrar2 now
domain.owner_contact.reload domain.reload
domain.owner_contact.registrar_id.should == @registrar2.id domain.owner_contact.registrar_id.should == @registrar2.id
# owner_contact should be a new record # owner_contact should be a new record
domain.owner_contact.id.should_not == original_oc_id domain.owner_contact.id.should_not == original_oc_id