Browse Source

Display available from date for absorbing orgs

pull/1997/head
Kat 3 years ago
parent
commit
b1097ca0a6
  1. 4
      app/models/form/lettings/questions/managing_organisation.rb
  2. 4
      app/models/form/lettings/questions/stock_owner.rb
  3. 4
      app/models/form/sales/questions/owning_organisation_id.rb
  4. 15
      spec/models/form/lettings/questions/managing_organisation_spec.rb
  5. 29
      spec/models/form/lettings/questions/stock_owner_spec.rb
  6. 29
      spec/models/form/sales/questions/owning_organisation_id_spec.rb

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

@ -23,8 +23,8 @@ 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? elsif user.organisation.absorbed_organisations.exists? && user.organisation.available_from.present?
opts[user.organisation.id] = "#{user.organisation.name} (Your organisation, active as of #{user.organisation.created_at.to_fs(:govuk_date)})" opts[user.organisation.id] = "#{user.organisation.name} (Your organisation, active as of #{user.organisation.available_from.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

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

@ -21,8 +21,8 @@ class Form::Lettings::Questions::StockOwner < ::Form::Question
recently_absorbed_organisations = user.organisation.absorbed_organisations.merged_during_open_collection_period recently_absorbed_organisations = user.organisation.absorbed_organisations.merged_during_open_collection_period
if !user.support? && user.organisation.holds_own_stock? if !user.support? && user.organisation.holds_own_stock?
answer_opts[user.organisation.id] = if recently_absorbed_organisations.exists? answer_opts[user.organisation.id] = if recently_absorbed_organisations.exists? && user.organisation.available_from.present?
"#{user.organisation.name} (Your organisation, active as of #{user.organisation.created_at.to_fs(:govuk_date)})" "#{user.organisation.name} (Your organisation, active as of #{user.organisation.available_from.to_fs(:govuk_date)})"
else else
"#{user.organisation.name} (Your organisation)" "#{user.organisation.name} (Your organisation)"
end end

4
app/models/form/sales/questions/owning_organisation_id.rb

@ -22,8 +22,8 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
recently_absorbed_organisations = user.organisation.absorbed_organisations.merged_during_open_collection_period recently_absorbed_organisations = user.organisation.absorbed_organisations.merged_during_open_collection_period
if !user.support? && user.organisation.holds_own_stock? if !user.support? && user.organisation.holds_own_stock?
answer_opts[user.organisation.id] = if recently_absorbed_organisations.exists? answer_opts[user.organisation.id] = if recently_absorbed_organisations.exists? && user.organisation.available_from.present?
"#{user.organisation.name} (Your organisation, active as of #{user.organisation.created_at.to_fs(:govuk_date)})" "#{user.organisation.name} (Your organisation, active as of #{user.organisation.available_from.to_fs(:govuk_date)})"
else else
"#{user.organisation.name} (Your organisation)" "#{user.organisation.name} (Your organisation)"
end end

15
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, created_at: Time.zone.local(2023, 8, 3)) } let(:absorbing_org) { create(:organisation, name: "Absorbing org", holds_own_stock: true) }
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) }
@ -173,6 +173,17 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
end end
it "displays merged organisation on the list of choices" do it "displays merged organisation on the list of choices" do
options = {
"" => "Select an option",
absorbing_org.id => "Absorbing org (Your organisation)",
merged_org.id => "Merged org (inactive as of 2 August 2023)",
merged_org.id => "Merged org (inactive as of 2 August 2023)",
}
expect(question.displayed_answer_options(log, user)).to eq(options)
end
it "displays active date for absorbing organisation if available from is given" do
absorbing_org.update!(available_from: Time.zone.local(2023, 8, 3))
options = { options = {
"" => "Select an option", "" => "Select an option",
absorbing_org.id => "Absorbing org (Your organisation, active as of 3 August 2023)", absorbing_org.id => "Absorbing org (Your organisation, active as of 3 August 2023)",
@ -189,7 +200,7 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
options = { options = {
"" => "Select an option", "" => "Select an option",
merged_org.id => "Merged org (inactive as of 2 August 2023)", merged_org.id => "Merged org (inactive as of 2 August 2023)",
absorbing_org.id => "Absorbing org (Your organisation, active as of 3 August 2023)", absorbing_org.id => "Absorbing org (Your organisation)",
managing_agent.id => "Managing org 1", managing_agent.id => "Managing org 1",
} }

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

@ -101,7 +101,7 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
end end
end end
context "when user's org has recently absorbed other orgs" do context "when user's org has recently absorbed other orgs and has available_from date" do
let(:merged_organisation) { create(:organisation, name: "Merged org") } let(:merged_organisation) { create(:organisation, name: "Merged org") }
let(:options) do let(:options) do
{ {
@ -115,7 +115,28 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
before do before do
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
user.organisation.update!(created_at: Time.zone.local(2021, 2, 2)) user.organisation.update!(available_from: Time.zone.local(2021, 2, 2))
end
it "shows merged organisation as an option" do
expect(question.displayed_answer_options(log, user)).to eq(options)
end
end
context "when user's org has recently absorbed other orgs and does not have available from date" do
let(:merged_organisation) { create(:organisation, name: "Merged org") }
let(:options) do
{
"" => "Select an option",
user.organisation.id => "User org (Your organisation)",
owning_org_2.id => "Owning org 2",
owning_org_1.id => "Owning org 1",
merged_organisation.id => "Merged org (inactive as of 2 February 2023)",
}
end
before do
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
end end
it "shows merged organisation as an option" do it "shows merged organisation as an option" do
@ -137,7 +158,7 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
before do before do
org_rel.update!(child_organisation: merged_organisation) org_rel.update!(child_organisation: merged_organisation)
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
user.organisation.update!(created_at: Time.zone.local(2021, 2, 2)) user.organisation.update!(available_from: Time.zone.local(2021, 2, 2))
end end
it "does not show merged organisations stock owners as options" do it "does not show merged organisations stock owners as options" do
@ -159,7 +180,7 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
Timecop.freeze(Time.zone.local(2023, 4, 2)) Timecop.freeze(Time.zone.local(2023, 4, 2))
org_rel.update!(child_organisation: merged_organisation) org_rel.update!(child_organisation: merged_organisation)
merged_organisation.update!(merge_date: Time.zone.local(2021, 6, 2), absorbing_organisation: user.organisation) merged_organisation.update!(merge_date: Time.zone.local(2021, 6, 2), absorbing_organisation: user.organisation)
user.organisation.update!(created_at: Time.zone.local(2021, 2, 2)) user.organisation.update!(available_from: Time.zone.local(2021, 2, 2))
end end
it "shows merged organisation as an option" do it "shows merged organisation as an option" do

29
spec/models/form/sales/questions/owning_organisation_id_spec.rb

@ -98,7 +98,7 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
let(:options) do let(:options) do
{ {
"" => "Select an option", "" => "Select an option",
user.organisation.id => "User org (Your organisation, active as of 2 February 2021)", user.organisation.id => "User org (Your organisation)",
owning_org_1.id => "Owning org 1", owning_org_1.id => "Owning org 1",
merged_organisation.id => "Merged org (inactive as of 2 February 2023)", merged_organisation.id => "Merged org (inactive as of 2 February 2023)",
} }
@ -106,7 +106,6 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
before do before do
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
user.organisation.update!(created_at: Time.zone.local(2021, 2, 2))
end end
it "shows merged organisation as an option" do it "shows merged organisation as an option" do
@ -114,7 +113,7 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
end end
end end
context "when user's org has recently absorbed other orgs with parent organisations" do context "when user's org has recently absorbed other orgs and it has available from date" do
let(:merged_organisation) { create(:organisation, name: "Merged org") } let(:merged_organisation) { create(:organisation, name: "Merged org") }
let(:options) do let(:options) do
{ {
@ -125,10 +124,30 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
} }
end end
before do
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
user.organisation.update!(available_from: Time.zone.local(2021, 2, 2))
end
it "shows available from date if it is given" do
expect(question.displayed_answer_options(log, user)).to eq(options)
end
end
context "when user's org has recently absorbed other orgs with parent organisations" do
let(:merged_organisation) { create(:organisation, name: "Merged org") }
let(:options) do
{
"" => "Select an option",
user.organisation.id => "User org (Your organisation)",
owning_org_1.id => "Owning org 1",
merged_organisation.id => "Merged org (inactive as of 2 February 2023)",
}
end
before do before do
org_rel.update!(child_organisation: merged_organisation) org_rel.update!(child_organisation: merged_organisation)
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
user.organisation.update!(created_at: Time.zone.local(2021, 2, 2))
end end
it "does not show merged organisations stock owners as options" do it "does not show merged organisations stock owners as options" do
@ -150,7 +169,7 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
Timecop.freeze(Time.zone.local(2023, 4, 2)) Timecop.freeze(Time.zone.local(2023, 4, 2))
org_rel.update!(child_organisation: merged_organisation) org_rel.update!(child_organisation: merged_organisation)
merged_organisation.update!(merge_date: Time.zone.local(2021, 6, 2), absorbing_organisation: user.organisation) merged_organisation.update!(merge_date: Time.zone.local(2021, 6, 2), absorbing_organisation: user.organisation)
user.organisation.update!(created_at: Time.zone.local(2021, 2, 2)) user.organisation.update!(available_from: Time.zone.local(2021, 2, 2))
end end
it "shows merged organisation as an option" do it "shows merged organisation as an option" do

Loading…
Cancel
Save