From 1341cd51dd4e7c3b096387e5dcc416f464fc54ad Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 9 Aug 2023 15:23:21 +0100 Subject: [PATCH] Do not show stock owners in sales logs owning org options --- .../sales/questions/owning_organisation_id.rb | 5 +--- .../questions/owning_organisation_id_spec.rb | 27 +++---------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/app/models/form/sales/questions/owning_organisation_id.rb b/app/models/form/sales/questions/owning_organisation_id.rb index 81757207d..7e3e2a43d 100644 --- a/app/models/form/sales/questions/owning_organisation_id.rb +++ b/app/models/form/sales/questions/owning_organisation_id.rb @@ -27,15 +27,12 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question end end - user_organisation_options = user.support? ? Organisation.where(holds_own_stock: true) : user.organisation.stock_owners + user_organisation_options = user.support? ? Organisation.where(holds_own_stock: true) : Organisation.none user_answer_options = user_organisation_options.pluck(:id, :name).to_h unless user.support? recently_absorbed_organisations.each do |absorbed_org| answer_opts[absorbed_org.id] = merged_organisation_label(absorbed_org.name, absorbed_org.merge_date) if absorbed_org.holds_own_stock? - absorbed_org.stock_owners.each do |stock_owner| - user_answer_options[stock_owner.id] = merged_organisation_label(stock_owner.name, absorbed_org.merge_date) - end end end diff --git a/spec/models/form/sales/questions/owning_organisation_id_spec.rb b/spec/models/form/sales/questions/owning_organisation_id_spec.rb index f7d5a79a7..19705e1e9 100644 --- a/spec/models/form/sales/questions/owning_organisation_id_spec.rb +++ b/spec/models/form/sales/questions/owning_organisation_id_spec.rb @@ -70,31 +70,13 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do "" => "Select an option", owning_org_1.id => "Owning org 1", user.organisation.id => "User org (Your organisation)", - owning_org_2.id => "Owning org 2", } end - it "shows current stock owner at top, followed by user's org (with hint), followed by the stock owners of the user's org" do + it "does not show stock owner" do user.organisation.update!(holds_own_stock: true) expect(question.displayed_answer_options(log, user)).to eq(options) end - - context "when the owning-managing organisation relationship is deleted" do - let(:options) do - { - "" => "Select an option", - user.organisation.id => "User org (Your organisation)", - owning_org_2.id => "Owning org 2", - } - end - - it "doesn't remove the housing provider from the list of allowed housing providers" do - log.update!(owning_organisation: owning_org_2) - expect(question.displayed_answer_options(log, user)).to eq(options) - org_rel.destroy! - expect(question.displayed_answer_options(log, user)).to eq(options) - end - end end context "when user's org doesn't own stock" do @@ -102,11 +84,10 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do { "" => "Select an option", owning_org_1.id => "Owning org 1", - owning_org_2.id => "Owning org 2", } end - it "shows current stock owner at top, followed by the stock owners of the user's org" do + it "shows current log owner" do user.organisation.update!(holds_own_stock: false) expect(question.displayed_answer_options(log, user)).to eq(options) end @@ -120,7 +101,6 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do user.organisation.id => "User org (Your organisation, active as of 2 February 2021)", owning_org_1.id => "Owning org 1", merged_organisation.id => "Merged org (inactive as of 2 February 2023)", - owning_org_2.id => "Owning org 2", } end @@ -142,7 +122,6 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do user.organisation.id => "User org (Your organisation, active as of 2 February 2021)", owning_org_1.id => "Owning org 1", merged_organisation.id => "Merged org (inactive as of 2 February 2023)", - owning_org_2.id => "Owning org 2 (inactive as of 2 February 2023)", } end @@ -152,7 +131,7 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do user.organisation.update!(created_at: Time.zone.local(2021, 2, 2)) end - it "shows merged organisations stock owners as options" do + it "does not show merged organisations stock owners as options" do expect(question.displayed_answer_options(log, user)).to eq(options) end end