From 33f7920ad86b2e4abf8514069caba1603ec7ffc6 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Wed, 11 Mar 2015 19:01:58 +0200 Subject: [PATCH] Clone owner contact if contact has more domains --- Gemfile | 5 ++++- Gemfile.lock | 3 +++ app/models/epp/domain.rb | 10 ++++++++-- spec/epp/domain_spec.rb | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index e0bf28b53..45677bcda 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem 'pg', '~> 0.18.0' gem 'ransack', '~> 1.5.1' # for searching # with polymorphic fix gem 'paper_trail', - github: 'airblade/paper_trail', + github: 'airblade/paper_trail', ref: 'a453811226ec4ea59753ba6b827e390ced2fc140' # '~> 4.0.0.beta2' # archiving gem 'rails-settings-cached', '~> 0.4.1' # for settings gem 'delayed_job_active_record', '~> 4.0.3' # delayed job @@ -60,6 +60,9 @@ gem 'newrelic_rpm', '~> 3.9.9.275' # country listing gem 'countries', '~> 0.10.0' +# cloning activerecord objects +gem 'deep_cloneable', '~> 2.1.1' + group :development do # dev tools gem 'spring', '~> 1.2.0' diff --git a/Gemfile.lock b/Gemfile.lock index 478d7604a..c38ea00cf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -122,6 +122,8 @@ GEM daemons (1.1.9) database_cleaner (1.3.0) debug_inspector (0.0.2) + deep_cloneable (2.1.1) + activerecord (>= 3.1.0, < 5.0.0) delayed_job (4.0.6) activesupport (>= 3.0, < 5.0) delayed_job_active_record (4.0.3) @@ -455,6 +457,7 @@ DEPENDENCIES countries (~> 0.10.0) daemons (~> 1.1.9) database_cleaner (~> 1.3.0) + deep_cloneable (~> 2.1.1) delayed_job_active_record (~> 4.0.3) devise (~> 3.4.1) epp (~> 1.4.0) diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index eb71e4c73..f68a42d92 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -401,8 +401,14 @@ class Epp::Domain < Domain end def transfer_contacts(current_user) - if owner_contact.domains.count > 1 - # create new + if owner_contact.domains_owned.count > 1 + 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 # transfer contact # TODO: This is a workaround so Bullet won't complain about n+1 query diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 635807e1f..22c773940 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -914,7 +914,7 @@ describe 'EPP Domain', epp: true do end # all domain contacts should be under registrar2 now - domain.owner_contact.reload + domain.reload domain.owner_contact.registrar_id.should == @registrar2.id # owner_contact should be a new record domain.owner_contact.id.should_not == original_oc_id