mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 09:43:36 +02:00
Merge branch 'master' of github.com:internetee/registry
This commit is contained in:
commit
fe54f327d9
2 changed files with 19 additions and 35 deletions
|
@ -70,25 +70,16 @@ class Contact < ActiveRecord::Base
|
||||||
Domain.find_by(owner_contact_id: id)
|
Domain.find_by(owner_contact_id: id)
|
||||||
end
|
end
|
||||||
|
|
||||||
#TODO Refactor the relation methods to something more sensible
|
def relations_with_domain?
|
||||||
def get_relation( model = :domain_contacts )
|
return true if domain_contacts.present? || domains_owned.present?
|
||||||
send(model)
|
return false
|
||||||
rescue NoMethodError => e
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def has_relation( model = :domain_contacts )
|
|
||||||
relation = get_relation(model)
|
|
||||||
return true unless relation.nil? || relation.blank?
|
|
||||||
false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#should use only in transaction
|
#should use only in transaction
|
||||||
def destroy_and_clean
|
def destroy_and_clean
|
||||||
clean_up_address
|
clean_up_address
|
||||||
|
|
||||||
if has_relation(:domain_contacts) || domains_owned.present?
|
if relations_with_domain?
|
||||||
#errors.add(:contact, msg: I18n.t('errors.messages.epp_obj_association_error'), value: { obj: 'contact', val: code })
|
|
||||||
errors.add(:domains, :exist)
|
errors.add(:domains, :exist)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,30 +39,23 @@ describe Contact do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Contact, '#get_relation' do
|
describe Contact, '#relations_with_domain?' do
|
||||||
|
context 'with no relation' do
|
||||||
before(:each) { Fabricate(:contact) }
|
before(:each) { Fabricate(:contact) }
|
||||||
it 'should return nil if no method' do
|
it 'should return false' do
|
||||||
expect(Contact.first.get_relation(:chewbacca)).to eq nil
|
expect(Contact.first.relations_with_domain?).to be false
|
||||||
end
|
|
||||||
|
|
||||||
it 'should return domain_contacts by default' do
|
|
||||||
expect(Contact.first.get_relation).to eq []
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Contact, '#has_relation' do
|
context 'with relation' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
Fabricate(:domain_validation_setting_group)
|
Fabricate(:domain_validation_setting_group)
|
||||||
Fabricate(:domain)
|
Fabricate(:domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return false if no relation' do
|
it 'should return true' do
|
||||||
expect(Contact.last.has_relation(:chewbacca)).to eq false
|
expect(Contact.first.relations_with_domain?).to be true
|
||||||
end
|
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue