diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index b430136ae..db31fb12a 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -19,7 +19,7 @@ class OrganisationsController < ApplicationController end def schemes - all_schemes = Scheme.where(owning_organisation: @organisation).order_by_completion.order_by_service_name + all_schemes = Scheme.where(owning_organisation: [@organisation] + @organisation.parent_organisations).order_by_completion.order_by_service_name @pagy, @schemes = pagy(filtered_collection(all_schemes, search_term)) @searched = search_term.presence diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 9c4775931..81fe920c4 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -39,6 +39,9 @@ RSpec.describe SchemesController, type: :request do let(:user) { FactoryBot.create(:user, :data_coordinator) } before do + schemes.each do |scheme| + scheme.update!(owning_organisation: user.organisation) + end sign_in user get "/schemes" end @@ -47,6 +50,33 @@ RSpec.describe SchemesController, type: :request do follow_redirect! expect(path).to match("/organisations/#{user.organisation.id}/schemes") end + + it "shows a list of schemes for the organisation" do + follow_redirect! + schemes.each do |scheme| + expect(page).to have_content(scheme.id_to_display) + end + end + + context "when parent organisation has schemes" do + let(:parent_organisation) { FactoryBot.create(:organisation) } + let!(:parent_schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation: parent_organisation) } + + before do + create(:organisation_relationship, parent_organisation:, child_organisation: user.organisation) + parent_schemes.each do |scheme| + FactoryBot.create(:location, scheme:) + end + get "/schemes" + end + + it "shows parent organisation schemes" do + follow_redirect! + parent_schemes.each do |scheme| + expect(page).to have_content(scheme.id_to_display) + end + end + end end context "when signed in as a support user" do