Browse Source

only display schemes with managing org id

pull/775/head
Kat 3 years ago
parent
commit
3246d8b380
  1. 2
      app/models/form/setup/questions/scheme_id.rb
  2. 8
      spec/features/schemes_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) def displayed_answer_options(case_log)
organisation = case_log.owning_organisation || case_log.created_by&.organisation 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) 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|
filtered_scheme_ids.include?(k.to_i) || k.blank? filtered_scheme_ids.include?(k.to_i) || k.blank?

8
spec/features/schemes_spec.rb

@ -843,7 +843,7 @@ RSpec.describe "Schemes scheme Features" do
context "when selecting a scheme" do context "when selecting a scheme" do
let!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) } 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(:location) { FactoryBot.create(:location, scheme: schemes[2]) }
let!(:case_log) { FactoryBot.create(:case_log, created_by: user, needstype: 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") visit("/logs/#{case_log.id}/scheme")
expect(find("#case-log-scheme-id-field").all("option").count).to eq(4) expect(find("#case-log-scheme-id-field").all("option").count).to eq(4)
end 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
end end

Loading…
Cancel
Save