diff --git a/app/models/contact.rb b/app/models/contact.rb index 44af31d65..d1ea2da63 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -51,6 +51,9 @@ class Contact < ActiveRecord::Base manage_ok end + # for overwrite when doing children loop + attr_writer :domains_present + scope :current_registrars, ->(id) { where(registrar_id: id) } BIC = 'bic' @@ -313,11 +316,6 @@ class Contact < ActiveRecord::Base domain_contacts.present? || registrant_domains.present? end - # for overwrite when doing children loop - def domains_present=(boolean) - @domains_present = boolean - end - def manage_linked if domains_present? set_linked diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 73c015904..c36912d6b 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -528,7 +528,7 @@ class Epp::Domain < Domain return if registrant.registrar_id == registrar_id is_other_domains_contact = DomainContact.where('contact_id = ? AND domain_id != ?', registrant_id, id).count > 0 - if registrant.domains_owned.count > 1 || is_other_domains_contact + if registrant.registrant_domains.count > 1 || is_other_domains_contact oc = copy_and_transfer_contact(registrant_id, registrar_id) self.registrant_id = oc.id else diff --git a/app/views/admin/contacts/partials/_domains.haml b/app/views/admin/contacts/partials/_domains.haml index 142c06397..0c319127b 100644 --- a/app/views/admin/contacts/partials/_domains.haml +++ b/app/views/admin/contacts/partials/_domains.haml @@ -8,7 +8,7 @@ %th{class: 'col-xs-4'}= t(:registrar) %th{class: 'col-xs-4'}= t(:valid_to) %tbody - - @contact.domains_owned.each do |x| + - @contact.registrant_domains.each do |x| %tr %td= link_to(x.name, [:admin, x]) %td= link_to(x.registrar, [:admin, x.registrar]) diff --git a/spec/fabricators/domain_fabricator.rb b/spec/fabricators/domain_fabricator.rb index 80d8bf598..24f7a45f4 100644 --- a/spec/fabricators/domain_fabricator.rb +++ b/spec/fabricators/domain_fabricator.rb @@ -3,7 +3,7 @@ Fabricator(:domain) do valid_to Date.new(2014, 8, 7) period 1 period_unit 'y' - registrant(fabricator: :registrant) + registrant { Fabricate(:registrant) } nameservers(count: 3) admin_domain_contacts(count: 1) { Fabricate(:admin_domain_contact) } tech_domain_contacts(count: 1) { Fabricate(:tech_domain_contact) } diff --git a/spec/mailers/contact_mailer_spec.rb b/spec/mailers/contact_mailer_spec.rb index 9f825b380..fe4ccc84c 100644 --- a/spec/mailers/contact_mailer_spec.rb +++ b/spec/mailers/contact_mailer_spec.rb @@ -29,6 +29,7 @@ describe ContactMailer do before :all do @domain = Fabricate(:domain) @contact = @domain.registrant + @contact.reload # until figured out why registrant_domains not loaded @contact.deliver_emails = true @contact.email = 'test@example.org' # new email @mail = ContactMailer.email_updated(@contact) diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 721039f14..6cc3ee124 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -137,8 +137,8 @@ describe Contact do end end - it 'should not have relation' do - @contact.relations_with_domain?.should == false + it 'should not have relation with domains' do + @contact.domains_present?.should == false end it 'bic should be valid' do @@ -234,9 +234,15 @@ describe Contact do it 'should have related domain descriptions hash' do contact = @domain.registrant + contact.reload # somehow it registrant_domains are empty? contact.related_domain_descriptions.should == { "#{@domain.name}" => [:registrant] } end + it 'should have related domain descriptions hash when find directly' do + contact = @domain.registrant + Contact.find(contact.id).related_domain_descriptions.should == { "#{@domain.name}" => [:registrant] } + end + it 'should have related domain descriptions hash' do contact = @domain.contacts.first contact.related_domain_descriptions.should == { "#{@domain.name}" => [:admin] } diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 453d8fc13..c36859300 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -48,6 +48,7 @@ def create_settings Setting.client_side_status_editing_enabled = true + # speedup and easier to create fabrications @fixed_registrar = Registrar.find_by_name('fixed registrar') || Fabricate(:registrar, name: 'fixed registrar', code: 'FIXED')