diff --git a/app/models/contact.rb b/app/models/contact.rb index bcfb6b61f..9d554ecf0 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -70,25 +70,16 @@ class Contact < ActiveRecord::Base Domain.find_by(owner_contact_id: id) end - #TODO Refactor the relation methods to something more sensible - def get_relation( model = :domain_contacts ) - send(model) - rescue NoMethodError => e - nil - end - - def has_relation( model = :domain_contacts ) - relation = get_relation(model) - return true unless relation.nil? || relation.blank? - false + def relations_with_domain? + return true if domain_contacts.present? || domains_owned.present? + return false end #should use only in transaction def destroy_and_clean clean_up_address - if has_relation(:domain_contacts) || domains_owned.present? - #errors.add(:contact, msg: I18n.t('errors.messages.epp_obj_association_error'), value: { obj: 'contact', val: code }) + if relations_with_domain? errors.add(:domains, :exist) return false end diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 2d37e63af..3fae6fc92 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -39,30 +39,23 @@ describe Contact do end end -describe Contact, '#get_relation' do - before(:each) { Fabricate(:contact) } - it 'should return nil if no method' do - expect(Contact.first.get_relation(:chewbacca)).to eq nil +describe Contact, '#relations_with_domain?' do + context 'with no relation' do + before(:each) { Fabricate(:contact) } + it 'should return false' do + expect(Contact.first.relations_with_domain?).to be false + end end - it 'should return domain_contacts by default' do - expect(Contact.first.get_relation).to eq [] - end -end - -describe Contact, '#has_relation' do - before(:each) do - Fabricate(:domain_validation_setting_group) - Fabricate(:domain) - end - - it 'should return false if no relation' do - expect(Contact.last.has_relation(:chewbacca)).to eq false - end - - it 'should return true if relation' do - expect(Contact.last.has_relation).to eq true - expect(Contact.last.has_relation(:address)).to eq true + context 'with relation' do + before(:each) do + Fabricate(:domain_validation_setting_group) + Fabricate(:domain) + end + + it 'should return true' do + expect(Contact.first.relations_with_domain?).to be true + end end end