Browse Source

Only display recent merges for absorbing org

pull/1996/head
Kat 3 years ago
parent
commit
81c3e897b8
  1. 4
      app/models/organisation.rb
  2. 2
      app/views/organisations/_merged_organisation_details.html.erb
  3. 18
      spec/requests/organisations_controller_spec.rb

4
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

2
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 %>
<p>Merge date: <%= @organisation.recent_merge_date&.to_formatted_s(:govuk_date) %></p>
<%= govuk_table do |table| %>

18
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") }

Loading…
Cancel
Save