From a5de802705662d3859f6f8205ff1b31d9be9f459 Mon Sep 17 00:00:00 2001 From: Jack S <113976590+bibblobcode@users.noreply.github.com> Date: Thu, 17 Nov 2022 17:33:02 +0000 Subject: [PATCH] [CLDC-20] Bugfix (#1005) Housing provider should be set to user's organisation if no housing providers are available for that organisation --- .../form/lettings/pages/housing_provider.rb | 7 ++--- .../lettings/pages/housing_provider_spec.rb | 27 +++---------------- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/app/models/form/lettings/pages/housing_provider.rb b/app/models/form/lettings/pages/housing_provider.rb index a1c3a6687..b63f71a7e 100644 --- a/app/models/form/lettings/pages/housing_provider.rb +++ b/app/models/form/lettings/pages/housing_provider.rb @@ -18,12 +18,9 @@ class Form::Lettings::Pages::HousingProvider < ::Form::Page return true if current_user.support? return true unless current_user.organisation.holds_own_stock? - housing_providers = current_user.organisation.housing_providers + return true if current_user.organisation.housing_providers.count.positive? - return false if housing_providers.count.zero? - return true if housing_providers.count > 1 - - log.update!(owning_organisation: housing_providers.first) + log.update!(owning_organisation: current_user.organisation) false end diff --git a/spec/models/form/lettings/pages/housing_provider_spec.rb b/spec/models/form/lettings/pages/housing_provider_spec.rb index 97420506e..9cf3bce6a 100644 --- a/spec/models/form/lettings/pages/housing_provider_spec.rb +++ b/spec/models/form/lettings/pages/housing_provider_spec.rb @@ -82,12 +82,12 @@ RSpec.describe Form::Lettings::Pages::HousingProvider, type: :model do expect(page.routed_to?(log, user)).to eq(false) end - it "does not update owning_organisation_id" do - expect { page.routed_to?(log, user) }.not_to change(log.reload, :owning_organisation).from(nil) + it "updates owning_organisation_id to user organisation" do + expect { page.routed_to?(log, user) }.to change(log.reload, :owning_organisation).from(nil).to(user.organisation) end end - context "with >1 housing_providers" do + context "with >0 housing_providers" do before do create(:organisation_relationship, :owning, child_organisation: user.organisation) create(:organisation_relationship, :owning, child_organisation: user.organisation) @@ -101,27 +101,6 @@ RSpec.describe Form::Lettings::Pages::HousingProvider, type: :model do expect { page.routed_to?(log, user) }.not_to change(log.reload, :owning_organisation).from(nil) end end - - context "with 1 housing_providers" do - let(:housing_provider) { create(:organisation) } - - before do - create( - :organisation_relationship, - :owning, - child_organisation: user.organisation, - parent_organisation: housing_provider, - ) - end - - it "is not shown" do - expect(page.routed_to?(log, user)).to eq(false) - end - - it "updates owning_organisation_id" do - expect { page.routed_to?(log, user) }.to change(log.reload, :owning_organisation).from(nil).to(housing_provider) - end - end end end end