Browse Source

Set correct merged managing organisation (#2071)

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

2
app/controllers/form_controller.rb

@ -108,6 +108,8 @@ private
result["managing_organisation_id"] = owning_organisation.id
elsif owning_organisation&.absorbing_organisation == current_user.organisation
result["managing_organisation_id"] = owning_organisation.id
elsif @log.managing_organisation&.absorbing_organisation == current_user.organisation && owning_organisation == current_user.organisation
result["managing_organisation_id"] = owning_organisation.id
end
end

28
spec/requests/form_controller_spec.rb

@ -853,6 +853,34 @@ RSpec.describe FormController, type: :request do
end
end
context "when owning organisation changes from merged organisation to absorbing user organisation" do
let(:params) do
{
id: lettings_log.id,
lettings_log: {
page: "stock_owner",
owning_organisation_id: organisation.id,
},
}
end
let(:merged_org) { create(:organisation) }
before do
merged_org.update!(merge_date: Time.zone.today, absorbing_organisation: organisation)
organisation.reload
lettings_log.update!(owning_organisation: merged_org, managing_organisation: merged_org, created_by: user)
lettings_log.reload
end
it "sets managing organisation to owning organisation" do
post "/lettings-logs/#{lettings_log.id}/stock-owner", params: params
follow_redirect!
lettings_log.reload
expect(lettings_log.owning_organisation).to eq(organisation)
expect(lettings_log.managing_organisation).to eq(organisation)
end
end
context "when the question was accessed from a duplicate logs screen" do
let(:lettings_log) { create(:lettings_log, :duplicate, created_by: user) }
let(:duplicate_log) { create(:lettings_log, :duplicate, created_by: user) }

Loading…
Cancel
Save