Browse Source

CLDC 1863: Prevent non-stock organisations appearing in search for who owns property questions. (#1748)

* CLDC-1863: orgs must own stock to show as option WIP

* CLDC-1863: Test updated

* CLDC-1863: removed test of no longer relevant behaviour
pull/1757/head
Aaron Spencer 1 year ago committed by GitHub
parent
commit
9349b6718d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/form/lettings/questions/stock_owner.rb
  2. 24
      spec/features/lettings_log_spec.rb
  3. 6
      spec/models/form/lettings/questions/stock_owner_spec.rb

2
app/models/form/lettings/questions/stock_owner.rb

@ -24,7 +24,7 @@ class Form::Lettings::Questions::StockOwner < ::Form::Question
end
stock_owners_answer_options = if user.support?
Organisation
Organisation.where(holds_own_stock: true)
else
user.organisation.stock_owners
end.pluck(:id, :name).to_h

24
spec/features/lettings_log_spec.rb

@ -132,30 +132,6 @@ RSpec.describe "Lettings Log Features" do
end
context "when the owning organisation question is answered" do
context "and the owning organisation doesn't hold stock" do
let(:managing_org) { create(:organisation, name: "Managing org") }
let!(:org_rel) { create(:organisation_relationship, parent_organisation: support_user.organisation, child_organisation: managing_org) }
before do
support_user.organisation.update!(holds_own_stock: false)
end
it "shows the managing organisation question" do
visit("/lettings-logs")
click_button("Create a new lettings log")
click_link("Set up this lettings log")
log_id = page.current_path.scan(/\d/).join
select(support_user.organisation.name, from: "lettings-log-owning-organisation-id-field")
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{log_id}/managing-organisation")
select(managing_org.name, from: "lettings-log-managing-organisation-id-field")
click_button("Save and continue")
visit("lettings-logs/#{log_id}/setup/check-answers")
expect(page).to have_content("Managing agent Managing org", normalize_ws: true)
expect(support_user.organisation.managing_agents).to eq([org_rel.child_organisation])
end
end
context "and the owning organisation does hold stock" do
before do
support_user.organisation.update!(holds_own_stock: true)

6
spec/models/form/lettings/questions/stock_owner_spec.rb

@ -107,15 +107,17 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
let(:log) { create(:lettings_log) }
let(:non_stock_organisation) { create(:organisation, holds_own_stock: false) }
let(:expected_opts) do
Organisation.all.each_with_object(options) do |organisation, hsh|
Organisation.where(holds_own_stock: true).each_with_object(options) do |organisation, hsh|
hsh[organisation.id] = organisation.name
hsh
end
end
it "shows all orgs" do
it "shows orgs where organisation holds own stock" do
expect(question.displayed_answer_options(log, user)).to eq(expected_opts)
expect(question.displayed_answer_options(log, user)).not_to include(non_stock_organisation.id)
end
end
end

Loading…
Cancel
Save