diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 8f3479cd6..25a3fdd0d 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -158,17 +158,17 @@ class Organisation < ApplicationRecord end def organisations_absorbed_during_displayed_collection_period_grouped_by_merge_date - return unless absorbed_organisations.present? && absorbed_organisations.merged_during_displayed_collection_period.present? + return unless absorbed_organisations.merged_during_displayed_collection_period.exists? absorbed_organisations.merged_during_displayed_collection_period.group_by(&:merge_date) end def has_recent_absorbed_organisations? - absorbed_organisations&.merged_during_open_collection_period.present? + absorbed_organisations.merged_during_open_collection_period.exists? end def has_organisations_absorbed_during_displayed_collection_period? - absorbed_organisations&.merged_during_displayed_collection_period.present? + absorbed_organisations.merged_during_displayed_collection_period.exists? end def organisation_or_stock_owner_signed_dsa_and_holds_own_stock? diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index a86816f4c..f30a1e4eb 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -381,14 +381,11 @@ RSpec.describe OrganisationsController, type: :request do end context "when the organisation has absorbed other organisations" do - let!(:absorbed_organisation) { create(:organisation, name: "First Absorbed Organisation") } - let!(:other_absorbed_organisation) { create(:organisation, name: "Other Absorbed Organisation") } - let!(:previously_absorbed_organisation) { create(:organisation, name: "Previously Absorbed Organisation") } + let!(:absorbed_organisation) { create(:organisation, name: "First Absorbed Organisation", with_dsa: false, merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation) } + let!(:other_absorbed_organisation) { create(:organisation, name: "Other Absorbed Organisation", with_dsa: false, merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation) } + let!(:previously_absorbed_organisation) { create(:organisation, name: "Previously Absorbed Organisation", with_dsa: false, merge_date: Time.zone.local(2023, 4, 2), absorbing_organisation: organisation) } before do - absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation) - other_absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation) - previously_absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 2), absorbing_organisation: organisation) get "/organisations/#{organisation.id}/details", headers:, params: {} end @@ -406,12 +403,9 @@ RSpec.describe OrganisationsController, type: :request do 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.today - 2.years, absorbing_organisation: organisation) - other_absorbed_organisation.update!(merge_date: Time.zone.today - 2.years, absorbing_organisation: organisation) + create(:organisation, name: "First Absorbed Organisation", with_dsa: false, merge_date: Time.zone.today - 2.years, absorbing_organisation: organisation) + create(:organisation, name: "Other Absorbed Organisation", with_dsa: false, merge_date: Time.zone.today - 2.years, absorbing_organisation: organisation) get "/organisations/#{organisation.id}/details", headers:, params: {} end @@ -423,12 +417,9 @@ RSpec.describe OrganisationsController, type: :request do end context "when the organisation has absorbed other organisations during a collection period before archived" 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.today - 3.years, absorbing_organisation: organisation) - other_absorbed_organisation.update!(merge_date: Time.zone.today - 3.years, absorbing_organisation: organisation) + create(:organisation, name: "First Absorbed Organisation", with_dsa: false, merge_date: Time.zone.today - 3.years, absorbing_organisation: organisation) + create(:organisation, name: "Other Absorbed Organisation", with_dsa: false, merge_date: Time.zone.today - 3.years, absorbing_organisation: organisation) get "/organisations/#{organisation.id}/details", headers:, params: {} end @@ -441,12 +432,10 @@ RSpec.describe OrganisationsController, type: :request do 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") } + let!(:absorbed_organisation) { create(:organisation, name: "First Absorbed Organisation", with_dsa: false, merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation) } + let!(:other_absorbed_organisation) { create(:organisation, name: "Other Absorbed Organisation", with_dsa: false, merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation) } before do - absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation) - other_absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation) get "/organisations/#{organisation.id}/details", headers:, params: {} end