diff --git a/app/models/contact.rb b/app/models/contact.rb index f6b180a5e..364a5d39e 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -188,7 +188,7 @@ class Contact < ActiveRecord::Base ver_scope << "(children->'#{type}')::jsonb <@ json_build_array(#{contact.id})::jsonb" 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 contact.in_use? + next if contact.linked? contact.destroy counter.next @@ -279,7 +279,7 @@ class Contact < ActiveRecord::Base calculated.delete(Contact::OK) calculated.delete(Contact::LINKED) calculated << Contact::OK if calculated.empty?# && valid? - calculated << Contact::LINKED if in_use? + calculated << Contact::LINKED if linked? calculated.uniq end @@ -345,7 +345,7 @@ class Contact < ActiveRecord::Base # no need separate method # should use only in transaction def destroy_and_clean frame - if in_use? + if linked? errors.add(:domains, :exist) return false end @@ -513,7 +513,7 @@ class Contact < ActiveRecord::Base Country.new(ident_country_code) end - def in_use? + def linked? registrant_domains.any? || domain_contacts.any? end diff --git a/app/presenters/registrant_presenter.rb b/app/presenters/registrant_presenter.rb index 6a78f86c5..4adf698e6 100644 --- a/app/presenters/registrant_presenter.rb +++ b/app/presenters/registrant_presenter.rb @@ -8,7 +8,7 @@ class RegistrantPresenter :reg_no, :street, :city, :state, :zip, :country, :ident_country, - :in_use?, + :linked?, to: :registrant def initialize(registrant:, view:) diff --git a/app/views/mailers/contact_mailer/email_changed.html.erb b/app/views/mailers/contact_mailer/email_changed.html.erb index 65801f756..35aa07cc3 100644 --- a/app/views/mailers/contact_mailer/email_changed.html.erb +++ b/app/views/mailers/contact_mailer/email_changed.html.erb @@ -10,7 +10,7 @@ uus aadress: <%= contact.email %>

E-posti aadressile saadetakse domeeni toimingutega seotud infot, sealhulgas kinnitustaotlused omanikuvahetuse ja domeeni kustutamise korral.

-<% if contact.in_use? %> +<% if contact.linked? %> Muudatusega seotud domeenid:
<%= contact.domain_names_with_roles(locale: :et, line_break: '
') %> <% end %> @@ -31,7 +31,7 @@ new address: <%= contact.email %>

E-mail addresses are used to send important information regarding your registered domains including applications for approval of registrant change and domain deletion. Please make sure that the update and contact information are correct.

-<% if contact.in_use? %> +<% if contact.linked? %> Domains affected by this update:
<%= contact.domain_names_with_roles(line_break: '
') %> <% end %> diff --git a/app/views/mailers/contact_mailer/email_changed.text.erb b/app/views/mailers/contact_mailer/email_changed.text.erb index 55d92d679..3b49fed80 100644 --- a/app/views/mailers/contact_mailer/email_changed.text.erb +++ b/app/views/mailers/contact_mailer/email_changed.text.erb @@ -10,7 +10,7 @@ uus aadress: <%= contact.email %> E-posti aadressile saadetakse domeeni toimingutega seotud infot, sealhulgas kinnitustaotlused omanikuvahetuse ja domeeni kustutamise korral. -<% if contact.in_use? %> +<% if contact.linked? %> Muudatusega seotud domeenid: <%= contact.domain_names_with_roles(locale: :et) %> <% end %> @@ -32,7 +32,7 @@ new address: <%= contact.email %> E-mail addresses are used to send important information regarding your registered domains including applications for approval of registrant change and domain deletion. Please make sure that the update and contact information are correct. -<% if contact.in_use? %> +<% if contact.linked? %> Domains affected by this update: <%= contact.domain_names_with_roles %> <% end %> diff --git a/spec/presenters/registrant_presenter_spec.rb b/spec/presenters/registrant_presenter_spec.rb index 8c7c7b6d3..224a0504f 100644 --- a/spec/presenters/registrant_presenter_spec.rb +++ b/spec/presenters/registrant_presenter_spec.rb @@ -67,7 +67,7 @@ RSpec.describe RegistrantPresenter do zip id_code reg_no - in_use? + linked? ) registrant_delegatable_attributes.each do |attr_name| diff --git a/test/models/contact/contact_test.rb b/test/models/contact/contact_test.rb index 0c4fc1e4e..e9301280e 100644 --- a/test/models/contact/contact_test.rb +++ b/test/models/contact/contact_test.rb @@ -13,18 +13,23 @@ class ContactTest < ActiveSupport::TestCase assert contacts(:invalid).invalid? end - def test_in_use_if_acts_as_a_registrant + def test_linked_when_in_use_as_registrant + Domain.update_all(registrant_id: @contact) DomainContact.delete_all - assert @contact.in_use? + + assert @contact.linked? end - def test_in_use_if_acts_as_a_domain_contact + def test_linked_when_in_use_as_domain_contact Domain.update_all(registrant_id: contacts(:william)) - assert @contact.in_use? + DomainContact.update_all(contact_id: @contact) + + assert @contact.linked? end - def test_not_in_use_if_acts_as_neither_registrant_nor_domain_contact - refute contacts(:not_in_use).in_use? + def test_unlinked_when_not_in_use_as_either_registrant_or_domain_contact + contact = unlinked_contact + assert_not contact.linked? end def test_managed_when_identity_codes_match @@ -38,4 +43,12 @@ class ContactTest < ActiveSupport::TestCase user = RegistrantUser.new(registrant_ident: 'US-12345') assert_not contact.managed_by?(user) end + + private + + def unlinked_contact + Domain.update_all(registrant_id: contacts(:william)) + DomainContact.delete_all + contacts(:john) + end end