Browse Source

Fix a bug with not finding a managing organisation field for sales (#1758)

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

2
app/controllers/form_controller.rb

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

26
spec/requests/form_controller_spec.rb

@ -163,6 +163,32 @@ RSpec.describe FormController, type: :request do
end end
end end
context "when submitting a sales log for organisation that doesn't have any managing agents" do
let(:sales_log) { create(:sales_log) }
let(:params) do
{
id: sales_log.id,
sales_log: {
page: "organisation",
owning_organisation_id: managing_organisation.id,
},
}
end
before do
sales_log.update!(owning_organisation: nil, created_by: nil)
sales_log.reload
end
it "correctly sets owning organisation" do
post "/sales-logs/#{sales_log.id}/organisation", params: params
expect(response).to redirect_to("/sales-logs/#{sales_log.id}/created-by")
follow_redirect!
sales_log.reload
expect(sales_log.owning_organisation).to eq(managing_organisation)
end
end
context "with valid managing organisation" do context "with valid managing organisation" do
let(:params) do let(:params) do
{ {

Loading…
Cancel
Save