From c405f8f3afa9ba7a73d2c23c803d85b0cb901229 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 25 Jul 2022 15:01:35 +0100 Subject: [PATCH] update context and query --- app/models/form/setup/questions/scheme_id.rb | 2 +- spec/requests/schemes_controller_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/form/setup/questions/scheme_id.rb b/app/models/form/setup/questions/scheme_id.rb index 6317e4c9d..27a9a6664 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).where(confirmed: true) : Scheme.select(:id).where(confirmed: true) + schemes = organisation ? Scheme.select(:id).where(owning_organisation_id: organisation.id, confirmed: true) : Scheme.select(:id).where(confirmed: true) 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/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 248ebc002..1b5a187fd 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -564,7 +564,7 @@ RSpec.describe SchemesController, type: :request do patch "/schemes/#{scheme_to_update.id}", params: end - context "when confirming the scheme" do + context "when confirming unfinished scheme" do let(:params) { { scheme: { owning_organisation_id: user.organisation.id, arrangement_type: "V", confirmed: true, page: "check-answers" } } } it "does not allow the scheme to be confirmed" do