From b8ce2fc5ad569854eab28a32fc934351ba8e9e35 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 19 Oct 2022 13:04:01 +0100 Subject: [PATCH] tests: add tests to org_controller and remove redundant housing_providers controller --- .../housing_providers_controller.rb | 28 ------ app/controllers/organisations_controller.rb | 6 +- .../requests/organisations_controller_spec.rb | 96 +++++++++++++++++++ 3 files changed, 101 insertions(+), 29 deletions(-) delete mode 100644 app/controllers/housing_providers_controller.rb diff --git a/app/controllers/housing_providers_controller.rb b/app/controllers/housing_providers_controller.rb deleted file mode 100644 index b3a014ada..000000000 --- a/app/controllers/housing_providers_controller.rb +++ /dev/null @@ -1,28 +0,0 @@ -class HousingProvidersController < ApplicationController - include Pagy::Backend - include Modules::SearchFilter - - def index - housing_providers = - Organisation.joins(:child_organisation_relationships) - .where(organisation_relationships: { - child_organisation_id: current_user.organisation_id, - relationship_type: OrganisationRelationship.relationship_types[:owning], - }) - .order(:name) - respond_to do |format| - format.html do - @pagy, @housing_providers = pagy(filtered_collection(housing_providers, search_term)) - @searched = search_term.presence - @total_count = housing_providers.size - render "housing_providers/index" - end - end - end - -private - - def search_term - params["search"] - end -end diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index ccc3f65b3..6baa0405d 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -149,7 +149,11 @@ class OrganisationsController < ApplicationController @pagy, @housing_providers = pagy(unpaginated_filtered_housing_providers) @searched = search_term.presence @total_count = housing_providers.size - render "housing_providers", layout: "application" + if current_user.support? + render "housing_providers", layout: "application" + else + render "housing_providers/index" + end end end end diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 6bc335921..ae36a6d88 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -284,6 +284,54 @@ RSpec.describe OrganisationsController, type: :request do end end + context "when accessing the housing providers tab" do + context "with an organisation that the user belongs to" do + let!(:housing_provider) { FactoryBot.create(:organisation) } + let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") } + let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") } + let!(:organisation_relationship) { FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) } + let!(:other_organisation_relationship) { FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) } + + before do + get "/organisations/#{organisation.id}/housing-providers", headers:, params: {} + end + + it "shows the tab navigation" do + expected_html = "