Browse Source

Fix scheme question when case log doesn't have an organisation yet

pull/774/head
baarkerlounger 3 years ago
parent
commit
5679cd2b6a
  1. 8
      app/models/form/setup/questions/scheme_id.rb
  2. 27
      spec/requests/form_controller_spec.rb

8
app/models/form/setup/questions/scheme_id.rb

@ -20,11 +20,11 @@ class Form::Setup::Questions::SchemeId < ::Form::Question
end end
def displayed_answer_options(case_log) def displayed_answer_options(case_log)
return {} unless case_log.created_by organisation = case_log.owning_organisation || case_log.created_by&.organisation
schemes = organisation ? Scheme.select(:id).where(owning_organisation_id: organisation.id) : Scheme.select(:id)
user_org_scheme_ids = Scheme.select(:id).where(owning_organisation_id: case_log.created_by.organisation_id).joins(:locations).merge(Location.where("startdate <= ? or startdate IS NULL", Time.zone.today)).map(&:id) 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| answer_options.select do |k, _v|
user_org_scheme_ids.include?(k.to_i) || k.blank? filtered_scheme_ids.include?(k.to_i) || k.blank?
end end
end end

27
spec/requests/form_controller_spec.rb

@ -93,6 +93,33 @@ RSpec.describe FormController, type: :request do
expect(response.body).to match("What counts as income?") expect(response.body).to match("What counts as income?")
end end
end end
context "when viewing the setup section schemes page" do
context "when the user is support" do
let(:user) { FactoryBot.create(:user, :support) }
context "when organisation and user have not been selected yet" do
let(:case_log) do
FactoryBot.create(
:case_log,
owning_organisation: nil,
managing_organisation: nil,
created_by: nil,
needstype: 2,
)
end
before do
FactoryBot.create_list(:location, 5)
end
it "returns an unfiltered list of schemes" do
get "/logs/#{case_log.id}/scheme", headers: headers, params: {}
expect(response.body.scan("<option value=").count).to eq(6)
end
end
end
end
end end
context "when displaying check answers pages" do context "when displaying check answers pages" do

Loading…
Cancel
Save