diff --git a/app/models/organisation.rb b/app/models/organisation.rb index eb4226614..5ba1f273d 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -156,4 +156,8 @@ class Organisation < ApplicationRecord absorbed_organisations.absorbed_on(recent_merge_date) end + + def has_absorbed_organisations_during_open_collection_period? + absorbed_organisations.any? && (recent_merge_date.blank? || recent_merge_date.present? && recent_merge_date > FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period) + end end diff --git a/app/views/organisations/_merged_organisation_details.html.erb b/app/views/organisations/_merged_organisation_details.html.erb index 67a336c20..ad11ff28c 100644 --- a/app/views/organisations/_merged_organisation_details.html.erb +++ b/app/views/organisations/_merged_organisation_details.html.erb @@ -1,4 +1,4 @@ -<% if @organisation.absorbed_organisations.any? %> +<% if @organisation.has_absorbed_organisations_during_open_collection_period? %> <%= govuk_details(summary_text: "View all organisations that were merged into #{@organisation.name}") do %>
Merge date: <%= @organisation.recent_merge_date&.to_formatted_s(:govuk_date) %>
<%= govuk_table do |table| %> diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 1bd19393e..7d27c71b9 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -308,6 +308,24 @@ RSpec.describe OrganisationsController, type: :request do end end + context "when the organisation has absorbed other organisations during a closed collection period" do + let!(:absorbed_organisation) { create(:organisation, name: "First Absorbed Organisation") } + let!(:other_absorbed_organisation) { create(:organisation, name: "Other Absorbed Organisation") } + + before do + absorbed_organisation.update!(merge_date: Time.zone.local(2021, 4, 3), absorbing_organisation: organisation) + other_absorbed_organisation.update!(merge_date: Time.zone.local(2021, 4, 3), absorbing_organisation: organisation) + get "/organisations/#{organisation.id}/details", headers:, params: {} + end + + it "does not display absorbed organisations" do + expect(page).not_to have_content("View all organisations that were merged into #{organisation.name}") + expect(page).not_to have_content("Merge date: 3 April 2021") + expect(page).not_to have_content("First Absorbed Organisation") + expect(page).not_to have_content("Other Absorbed Organisation") + end + end + context "when the organisation has absorbed other organisations without merge dates" do let!(:absorbed_organisation) { create(:organisation, name: "First Absorbed Organisation") } let!(:other_absorbed_organisation) { create(:organisation, name: "Other Absorbed Organisation") }