diff --git a/app/models/form/setup/questions/scheme_id.rb b/app/models/form/setup/questions/scheme_id.rb index cf6173591..a0a9a076f 100644 --- a/app/models/form/setup/questions/scheme_id.rb +++ b/app/models/form/setup/questions/scheme_id.rb @@ -21,7 +21,7 @@ class Form::Setup::Questions::SchemeId < ::Form::Question def displayed_answer_options(case_log) organisation = case_log.owning_organisation || case_log.created_by&.organisation - schemes = organisation ? Scheme.select(:id).where(owning_organisation_id: organisation.id) : Scheme.select(:id) + schemes = organisation ? Scheme.select(:id).where(owning_organisation_id: organisation.id).where.not(managing_organisation_id: nil) : Scheme.select(:id).where.not(managing_organisation_id: nil) filtered_scheme_ids = schemes.joins(:locations).merge(Location.where("startdate <= ? or startdate IS NULL", Time.zone.today)).map(&:id) answer_options.select do |k, _v| filtered_scheme_ids.include?(k.to_i) || k.blank? diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 82761d43d..d3d9ac321 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -843,7 +843,7 @@ RSpec.describe "Schemes scheme Features" do context "when selecting a scheme" do let!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) } - let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation: user.organisation) } + let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation: user.organisation, managing_organisation: user.organisation, arrangement_type: "The same organisation that owns the housing stock") } let(:location) { FactoryBot.create(:location, scheme: schemes[2]) } let!(:case_log) { FactoryBot.create(:case_log, created_by: user, needstype: 2) } @@ -886,5 +886,11 @@ RSpec.describe "Schemes scheme Features" do visit("/logs/#{case_log.id}/scheme") expect(find("#case-log-scheme-id-field").all("option").count).to eq(4) end + + it "does display the schemes that are not completed" do + schemes[2].update!(managing_organisation_id: nil) + visit("/logs/#{case_log.id}/scheme") + expect(find("#case-log-scheme-id-field").all("option").count).to eq(3) + end end end