Browse Source

Do not route to managing org if it can be inferred

pull/1747/head
Kat 3 years ago
parent
commit
0c73506ea5
  1. 1
      app/models/form/lettings/pages/managing_organisation.rb
  2. 21
      spec/models/form/lettings/pages/managing_organisation_spec.rb

1
app/models/form/lettings/pages/managing_organisation.rb

@ -20,6 +20,7 @@ class Form::Lettings::Pages::ManagingOrganisation < ::Form::Page
end
return false unless organisation
return false if log.owning_organisation != organisation && !organisation.holds_own_stock?
return true unless organisation.holds_own_stock?
organisation.managing_agents.count >= 1

21
spec/models/form/lettings/pages/managing_organisation_spec.rb

@ -105,15 +105,30 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
context "when not support" do
context "when does not hold own stock" do
let(:user) do
create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false))
end
let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false)) }
context "and the user's organisation is selected as owning organisation" do
let(:log) { create(:lettings_log, owning_organisation: user.organisation) }
it "is shown" do
expect(page.routed_to?(log, user)).to eq(true)
end
end
context "and a different than the user's organisation is selected as owning organisation" do
let(:stock_owner) { create(:organisation, holds_own_stock: true) }
let(:log) { create(:lettings_log, owning_organisation: stock_owner) }
before do
create(:organisation_relationship, parent_organisation: stock_owner, child_organisation: user.organisation)
end
it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false)
end
end
end
context "when holds own stock" do
let(:user) do
create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true))

Loading…
Cancel
Save