diff --git a/spec/models/form/lettings/questions/managing_organisation_spec.rb b/spec/models/form/lettings/questions/managing_organisation_spec.rb index 9977f07be..33c8fa3c6 100644 --- a/spec/models/form/lettings/questions/managing_organisation_spec.rb +++ b/spec/models/form/lettings/questions/managing_organisation_spec.rb @@ -135,6 +135,28 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do expect(question.displayed_answer_options(log, user)).to eq(options) end end + + context "when the owning-managing organisation relationship is deleted" do + let(:user) { create(:user, :support) } + let(:owning_org) { create(:organisation, name: "OwningOrg", holds_own_stock: true) } + let(:managing_org) { create(:organisation, name: "ManagingOrg", holds_own_stock: false) } + let!(:org_rel) { create(:organisation_relationship, parent_organisation: owning_org, child_organisation: managing_org) } + let(:log) { create(:lettings_log, owning_organisation: owning_org, managing_organisation: managing_org) } + + let(:options) do + { + "" => "Select an option", + owning_org.id => "OwningOrg (Owning organisation)", + managing_org.id => "ManagingOrg", + } + end + + it "doesn't remove the managing org from the list of allowed managing orgs" do + org_rel.destroy! + expect(question.displayed_answer_options(log, user)).to eq(options) + end + end + end it "is marked as derived" do