Browse Source

CLDC-2365 Set managing org to owning org if there are no managing agents (#1726)

* Set managing org to owning org if there are no managing agents

* Refactor condition
pull/1749/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
b129f2c624
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/controllers/form_controller.rb
  2. 26
      spec/requests/form_controller_spec.rb

8
app/controllers/form_controller.rb

@ -101,6 +101,14 @@ private
else
result[question.id] = question_params
end
if current_user.support? && question.id == "owning_organisation_id" && @log.managing_organisation.blank?
owning_organisation = Organisation.find(result["owning_organisation_id"])
if owning_organisation&.managing_agents&.empty?
result["managing_organisation_id"] = owning_organisation.id
end
end
result
end
end

26
spec/requests/form_controller_spec.rb

@ -136,6 +136,32 @@ RSpec.describe FormController, type: :request do
end
end
context "when owning organisation doesn't have any managing agents" do
let(:params) do
{
id: lettings_log.id,
lettings_log: {
page: "stock_owner",
owning_organisation_id: managing_organisation.id,
},
}
end
before do
lettings_log.update!(owning_organisation: nil, created_by: nil, managing_organisation: nil)
lettings_log.reload
end
it "sets managing organisation to owning organisation" do
post "/lettings-logs/#{lettings_log.id}/stock-owner", params: params
expect(response).to redirect_to("/lettings-logs/#{lettings_log.id}/created-by")
follow_redirect!
lettings_log.reload
expect(lettings_log.owning_organisation).to eq(managing_organisation)
expect(lettings_log.managing_organisation).to eq(managing_organisation)
end
end
context "with valid managing organisation" do
let(:params) do
{

Loading…
Cancel
Save