Browse Source

Display parent organisation's schemes in the list

pull/1637/head
Kat 3 years ago
parent
commit
ca9090f13d
  1. 2
      app/controllers/organisations_controller.rb
  2. 30
      spec/requests/schemes_controller_spec.rb

2
app/controllers/organisations_controller.rb

@ -19,7 +19,7 @@ class OrganisationsController < ApplicationController
end end
def schemes 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)) @pagy, @schemes = pagy(filtered_collection(all_schemes, search_term))
@searched = search_term.presence @searched = search_term.presence

30
spec/requests/schemes_controller_spec.rb

@ -39,6 +39,9 @@ RSpec.describe SchemesController, type: :request do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
before do before do
schemes.each do |scheme|
scheme.update!(owning_organisation: user.organisation)
end
sign_in user sign_in user
get "/schemes" get "/schemes"
end end
@ -47,6 +50,33 @@ RSpec.describe SchemesController, type: :request do
follow_redirect! follow_redirect!
expect(path).to match("/organisations/#{user.organisation.id}/schemes") expect(path).to match("/organisations/#{user.organisation.id}/schemes")
end 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 end
context "when signed in as a support user" do context "when signed in as a support user" do

Loading…
Cancel
Save