Remove duplicate method

#746
This commit is contained in:
Artur Beljajev 2018-03-06 12:26:35 +02:00
parent a910165bc9
commit bfbee65a49
3 changed files with 3 additions and 20 deletions

1
.reek
View file

@ -1066,7 +1066,6 @@ Attribute:
- BankStatement#th6_file - BankStatement#th6_file
- Versions#version_loader - Versions#version_loader
- Contact#deliver_emails - Contact#deliver_emails
- Contact#domains_present
- Contact#legal_document_id - Contact#legal_document_id
- Counter#value - Counter#value
- Deposit#amount - Deposit#amount

View file

@ -70,10 +70,6 @@ class Contact < ActiveRecord::Base
after_save :update_related_whois_records after_save :update_related_whois_records
# for overwrite when doing children loop
attr_writer :domains_present
scope :current_registrars, ->(id) { where(registrar_id: id) } scope :current_registrars, ->(id) { where(registrar_id: id) }
ORG = 'org' ORG = 'org'
@ -207,7 +203,7 @@ class Contact < ActiveRecord::Base
ver_scope << "(children->'#{type}')::jsonb <@ json_build_array(#{contact.id})::jsonb" ver_scope << "(children->'#{type}')::jsonb <@ json_build_array(#{contact.id})::jsonb"
end end
next if DomainVersion.where("created_at > ?", Time.now - Setting.orphans_contacts_in_months.to_i.months).where(ver_scope.join(" OR ")).any? next if DomainVersion.where("created_at > ?", Time.now - Setting.orphans_contacts_in_months.to_i.months).where(ver_scope.join(" OR ")).any?
next if contact.domains_present? next if contact.used?
contact.destroy contact.destroy
counter.next counter.next
@ -280,7 +276,7 @@ class Contact < ActiveRecord::Base
calculated.delete(Contact::OK) calculated.delete(Contact::OK)
calculated.delete(Contact::LINKED) calculated.delete(Contact::LINKED)
calculated << Contact::OK if calculated.empty?# && valid? calculated << Contact::OK if calculated.empty?# && valid?
calculated << Contact::LINKED if domains_present? calculated << Contact::LINKED if used?
calculated.uniq calculated.uniq
end end
@ -348,7 +344,7 @@ class Contact < ActiveRecord::Base
# no need separate method # no need separate method
# should use only in transaction # should use only in transaction
def destroy_and_clean frame def destroy_and_clean frame
if domains_present? if used?
errors.add(:domains, :exist) errors.add(:domains, :exist)
return false return false
end end
@ -406,14 +402,6 @@ class Contact < ActiveRecord::Base
end end
end end
# optimization under children loop,
# otherwise bullet will not be happy
def domains_present?
return @domains_present if @domains_present
domain_contacts.present? || registrant_domains.present?
end
def search_name def search_name
"#{code} #{name}" "#{code} #{name}"
end end

View file

@ -76,10 +76,6 @@ RSpec.describe Contact do
end end
end end
it 'should not have relation with domains' do
@contact.domains_present?.should == false
end
it 'should not overwrite code' do it 'should not overwrite code' do
old_code = @contact.code old_code = @contact.code
@contact.code = 'CID:REG1:should-not-overwrite-old-code-12345' @contact.code = 'CID:REG1:should-not-overwrite-old-code-12345'