Browse Source

Add absorbing org dates, fix copy

pull/1819/head
Kat 3 years ago
parent
commit
5a8978798c
  1. 12
      app/models/form/lettings/questions/managing_organisation.rb
  2. 12
      spec/models/form/lettings/questions/managing_organisation_spec.rb

12
app/models/form/lettings/questions/managing_organisation.rb

@ -23,22 +23,22 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
if log.owning_organisation.holds_own_stock? if log.owning_organisation.holds_own_stock?
opts[log.owning_organisation.id] = "#{log.owning_organisation.name} (Owning organisation)" opts[log.owning_organisation.id] = "#{log.owning_organisation.name} (Owning organisation)"
end end
elsif user.organisation.absorbed_organisations.exists?
opts[user.organisation.id] = "#{user.organisation.name} (Your organisation, active as of #{user.organisation.created_at.to_fs(:govuk_date)})"
else else
opts[user.organisation.id] = "#{user.organisation.name} (Your organisation)" opts[user.organisation.id] = "#{user.organisation.name} (Your organisation)"
end end
orgs = if user.support? orgs = if user.support?
log.owning_organisation.managing_agents log.owning_organisation.managing_agents
else elsif user.organisation.absorbed_organisations.include?(log.owning_organisation)
if user.organisation.absorbed_organisations.include?(log.owning_organisation)
user.organisation.managing_agents + log.owning_organisation.managing_agents user.organisation.managing_agents + log.owning_organisation.managing_agents
else else
user.organisation.managing_agents user.organisation.managing_agents
end
end.pluck(:id, :name).to_h end.pluck(:id, :name).to_h
user.organisation.absorbed_organisations.each do |absorbed_org| user.organisation.absorbed_organisations.each do |absorbed_org|
opts[absorbed_org.id] = "#{absorbed_org.name} (active until #{absorbed_org.merge_date.to_fs(:govuk_date)})" opts[absorbed_org.id] = "#{absorbed_org.name} (inactive as of #{absorbed_org.merge_date.to_fs(:govuk_date)})"
end end
opts.merge(orgs) opts.merge(orgs)

12
spec/models/form/lettings/questions/managing_organisation_spec.rb

@ -163,7 +163,7 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
end end
context "when organisation has merged" do context "when organisation has merged" do
let(:absorbing_org) { create(:organisation, name: "Absorbing org", holds_own_stock: true) } let(:absorbing_org) { create(:organisation, name: "Absorbing org", holds_own_stock: true, created_at: Time.zone.local(2023, 8, 3)) }
let!(:merged_org) { create(:organisation, name: "Merged org", holds_own_stock: false) } let!(:merged_org) { create(:organisation, name: "Merged org", holds_own_stock: false) }
let(:user) { create(:user, :data_coordinator, organisation: absorbing_org) } let(:user) { create(:user, :data_coordinator, organisation: absorbing_org) }
@ -175,9 +175,9 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
it "displays merged organisation on the list of choices" do it "displays merged organisation on the list of choices" do
options = { options = {
"" => "Select an option", "" => "Select an option",
absorbing_org.id => "Absorbing org (Your organisation)", absorbing_org.id => "Absorbing org (Your organisation, active as of 3 August 2023)",
merged_org.id => "Merged org (active until 2 August 2023)", merged_org.id => "Merged org (inactive as of 2 August 2023)",
merged_org.id => "Merged org (active until 2 August 2023)", merged_org.id => "Merged org (inactive as of 2 August 2023)",
} }
expect(question.displayed_answer_options(log, user)).to eq(options) expect(question.displayed_answer_options(log, user)).to eq(options)
end end
@ -188,8 +188,8 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
options = { options = {
"" => "Select an option", "" => "Select an option",
merged_org.id => "Merged org (active until 2 August 2023)", merged_org.id => "Merged org (inactive as of 2 August 2023)",
absorbing_org.id => "Absorbing org (Your organisation)", absorbing_org.id => "Absorbing org (Your organisation, active as of 3 August 2023)",
managing_agent.id => "Managing org 1", managing_agent.id => "Managing org 1",
} }

Loading…
Cancel
Save