Browse Source

update context and query

pull/775/head
Kat 3 years ago
parent
commit
c405f8f3af
  1. 2
      app/models/form/setup/questions/scheme_id.rb
  2. 2
      spec/requests/schemes_controller_spec.rb

2
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?

2
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

Loading…
Cancel
Save