Browse Source

Managing Organisation page should behave the same if user is support

pull/1012/head
Jack S 4 years ago
parent
commit
d55c789c73
  1. 1
      app/models/form/lettings/pages/managing_organisation.rb
  2. 59
      spec/models/form/lettings/pages/managing_organisation_spec.rb

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

@ -15,7 +15,6 @@ class Form::Lettings::Pages::ManagingOrganisation < ::Form::Page
def routed_to?(log, current_user) def routed_to?(log, current_user)
return false unless current_user return false unless current_user
return true if current_user.support?
return true unless current_user.organisation.holds_own_stock? return true unless current_user.organisation.holds_own_stock?
managing_agents = current_user.organisation.managing_agents managing_agents = current_user.organisation.managing_agents

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

@ -47,8 +47,40 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
end end
context "when support" do context "when support" do
let(:organisation) { create(:organisation) } context "when does not hold own stock" do
let(:user) { create(:user, :support, organisation:) } let(:user) do
create(:user, :support, organisation: create(:organisation, holds_own_stock: false))
end
it "is shown" do
expect(page.routed_to?(log, user)).to eq(true)
end
it "does not update managing_organisation_id" do
expect { page.routed_to?(log, user) }.not_to change(log.reload, :managing_organisation)
end
end
context "when holds own stock" do
let(:user) do
create(:user, :support, organisation: create(:organisation, holds_own_stock: true))
end
context "with 0 managing_agents" do
it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false)
end
it "does not update managing_organisation_id" do
expect { page.routed_to?(log, user) }.not_to change(log.reload, :managing_organisation)
end
end
context "with >1 managing_agents" do
before do
create(:organisation_relationship, :managing, parent_organisation: user.organisation)
create(:organisation_relationship, :managing, parent_organisation: user.organisation)
end
it "is shown" do it "is shown" do
expect(page.routed_to?(log, user)).to eq(true) expect(page.routed_to?(log, user)).to eq(true)
@ -59,6 +91,29 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
end end
end end
context "with 1 managing_agents" do
let(:managing_agent) { create(:organisation) }
before do
create(
:organisation_relationship,
:managing,
child_organisation: managing_agent,
parent_organisation: user.organisation,
)
end
it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false)
end
it "updates managing_organisation_id" do
expect { page.routed_to?(log, user) }.to change(log.reload, :managing_organisation).to(managing_agent)
end
end
end
end
context "when not support" do context "when not support" do
context "when does not hold own stock" do context "when does not hold own stock" do
let(:user) do let(:user) do

Loading…
Cancel
Save