Browse Source

[CLDC-20] Bugfix (#1005)

Housing provider should be set to user's organisation if no housing providers are available for that organisation
pull/1013/head
Jack S 2 years ago committed by GitHub
parent
commit
a5de802705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/models/form/lettings/pages/housing_provider.rb
  2. 27
      spec/models/form/lettings/pages/housing_provider_spec.rb

7
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 if current_user.support?
return true unless current_user.organisation.holds_own_stock? 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? log.update!(owning_organisation: current_user.organisation)
return true if housing_providers.count > 1
log.update!(owning_organisation: housing_providers.first)
false false
end end

27
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) expect(page.routed_to?(log, user)).to eq(false)
end end
it "does not update owning_organisation_id" do it "updates owning_organisation_id to user organisation" do
expect { page.routed_to?(log, user) }.not_to change(log.reload, :owning_organisation).from(nil) expect { page.routed_to?(log, user) }.to change(log.reload, :owning_organisation).from(nil).to(user.organisation)
end end
end end
context "with >1 housing_providers" do context "with >0 housing_providers" do
before do before do
create(:organisation_relationship, :owning, child_organisation: user.organisation) create(:organisation_relationship, :owning, child_organisation: user.organisation)
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) expect { page.routed_to?(log, user) }.not_to change(log.reload, :owning_organisation).from(nil)
end end
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 end
end end

Loading…
Cancel
Save