diff --git a/app/models/business_registry_cache.rb b/app/models/business_registry_cache.rb index 8ec3e0786..2e7c06cc8 100644 --- a/app/models/business_registry_cache.rb +++ b/app/models/business_registry_cache.rb @@ -19,24 +19,17 @@ authentication using electronic ID. Association through a business organisation =end class BusinessRegistryCache < ActiveRecord::Base - - # 1. load domains by business - # 2. load domains by person - def associated_contacts - contact_ids = Contact.where(ident_type: 'org', ident: associated_businesses, ident_country_code: 'EE').pluck(:id) - contact_ids += Contact.where(ident_type: 'priv', ident: ident, ident_country_code: ident_country_code).pluck(:id) - contact_ids - end - def associated_domain_ids + contact_ids = Contact.where(ident_type: 'org', ident: associated_businesses, ident_country_code: ident_country_code).pluck(:id) + contact_ids += Contact.where(ident_type: 'priv', ident: ident, ident_country_code: ident_country_code).pluck(:id) domain_ids = [] - contact_ids = associated_contacts - unless contact_ids.blank? domain_ids = DomainContact.distinct.where(contact_id: contact_ids).pluck(:domain_id) end + domain_ids += Domain.where(registrant_id: contact_ids).pluck(:id) + domain_ids end diff --git a/test/fixtures/business_registry_caches.yml b/test/fixtures/business_registry_caches.yml new file mode 100644 index 000000000..c55c98e0d --- /dev/null +++ b/test/fixtures/business_registry_caches.yml @@ -0,0 +1,8 @@ +first: + ident: 1234 + ident_country_code: US + associated_businesses: + - 1234 + retrieved_on: 2010-07-05 10:30 + created_at: 2010-07-05 10:30 + updated_at: 2010-07-05 10:30 diff --git a/test/fixtures/contacts.yml b/test/fixtures/contacts.yml new file mode 100644 index 000000000..0300ef2b6 --- /dev/null +++ b/test/fixtures/contacts.yml @@ -0,0 +1,20 @@ +john: + name: John + ident: 1234 + ident_type: priv + ident_country_code: US + registrar: acme + +jane: + name: Jane + ident: 1234 + ident_type: priv + ident_country_code: US + registrar: acme + +acme_ltd: + name: Acme Ltd. + ident: 1234 + ident_type: org + registrar: acme + ident_country_code: US diff --git a/test/fixtures/domain_contacts.yml b/test/fixtures/domain_contacts.yml new file mode 100644 index 000000000..3e1d01d62 --- /dev/null +++ b/test/fixtures/domain_contacts.yml @@ -0,0 +1,4 @@ +two_jane: + domain: two + contact: jane + type: AdminDomainContact diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml new file mode 100644 index 000000000..46a1e44e0 --- /dev/null +++ b/test/fixtures/domains.yml @@ -0,0 +1,14 @@ +one: + name: one.test + registrar: valid + registrant: john + +two: + name: two.test + registrar: valid + registrant: john + +three: + name: three.test + registrar: valid + registrant: acme_ltd diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 860f06c13..856788de9 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -14,3 +14,7 @@ admin: country_code: US roles: - admin + +registrant: + type: RegistrantUser + registrant_ident: US-1234 diff --git a/test/integration/registrant/domains_test.rb b/test/integration/registrant/domains_test.rb new file mode 100644 index 000000000..6a1a76e39 --- /dev/null +++ b/test/integration/registrant/domains_test.rb @@ -0,0 +1,25 @@ +require 'test_helper' + +class DomainsTest < ActionDispatch::IntegrationTest + def setup + login_as users(:registrant) + + Setting.days_to_keep_business_registry_cache = 1 + travel_to Time.zone.parse('2010-07-05') + end + + def test_shows_domains_where_current_user_is_registrant + visit registrant_domains_url + assert_text 'one.test' + end + + def test_shows_domains_where_current_user_is_contact_person + visit registrant_domains_url + assert_text 'two.test' + end + + def test_shows_domains_where_current_user_has_associated_organizations + visit registrant_domains_url + assert_text 'three.test' + end +end