Remove contact's address on domain transfer unless address_processing is enabled

#251
This commit is contained in:
Artur Beljajev 2016-12-14 05:49:13 +02:00
parent a63e2b9dd2
commit 68c3f0c338
3 changed files with 21 additions and 0 deletions

View file

@ -578,4 +578,9 @@ class Contact < ActiveRecord::Base
log
end
def remove_address
self.class.address_attribute_names.each do |attr_name|
self[attr_name.to_sym] = nil
end
end
end

View file

@ -648,6 +648,7 @@ class Epp::Domain < Domain
oc.copy_from_id = c.id
oc.generate_code
oc.domain_transfer = true
oc.remove_address unless Contact.address_processing?
oc.save!(validate: false)
oc
end

View file

@ -448,4 +448,19 @@ RSpec.describe Contact, db: false do
expect(contact.errors).to have_key(:country_code)
end
end
describe '#remove_address' do
let(:contact) { described_class.new(city: 'test',
street: 'test',
zip: 'test',
country_code: 'test',
state: 'test')
}
subject(:address_removed) { contact.attributes.slice(*described_class.address_attribute_names).compact.empty? }
it 'removes address attributes' do
contact.remove_address
expect(address_removed).to be_truthy
end
end
end