Browse Source

Deactivate locations on merged orgs

pull/2060/head
Kat 3 years ago
parent
commit
5f2ab7e65c
  1. 5
      app/services/merge/merge_organisations_service.rb
  2. 12
      spec/services/merge/merge_organisations_service_spec.rb

5
app/services/merge/merge_organisations_service.rb

@ -70,7 +70,10 @@ private
new_scheme = Scheme.create!(scheme.attributes.except("id", "owning_organisation_id", "old_id", "old_visible_id").merge(owning_organisation: @absorbing_organisation))
scheme.locations.each do |location|
new_scheme.locations << Location.new(location.attributes.except("id", "scheme_id", "old_id", "old_visible_id")) unless location.deactivated?
next if location.deactivated?
new_scheme.locations << Location.new(location.attributes.except("id", "scheme_id", "old_id", "old_visible_id"))
LocationDeactivationPeriod.create!(location:, deactivation_date: @merge_date)
end
@merged_schemes[merging_organisation.name] << { name: new_scheme.service_name, code: new_scheme.id }
SchemeDeactivationPeriod.create!(scheme:, deactivation_date: @merge_date)

12
spec/services/merge/merge_organisations_service_spec.rb

@ -167,6 +167,8 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(absorbing_organisation.owned_schemes.first.locations.first.old_visible_id).to be_nil
expect(scheme.scheme_deactivation_periods.count).to eq(1)
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
expect(scheme.locations.first.location_deactivation_periods.count).to eq(1)
expect(scheme.locations.first.location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
end
it "moves relevant logs and assigns the new scheme" do
@ -193,6 +195,7 @@ RSpec.describe Merge::MergeOrganisationsService do
merging_organisation.reload
expect(absorbing_organisation.owned_schemes.count).to eq(0)
expect(scheme.scheme_deactivation_periods.count).to eq(0)
expect(scheme.locations.first.location_deactivation_periods.count).to eq(0)
expect(owned_lettings_log.owning_organisation).to eq(merging_organisation)
expect(owned_lettings_log_no_location.owning_organisation).to eq(merging_organisation)
end
@ -333,6 +336,8 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode)
expect(scheme.scheme_deactivation_periods.count).to eq(1)
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday)
expect(scheme.locations.first.location_deactivation_periods.count).to eq(1)
expect(scheme.locations.first.location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday)
end
it "moves relevant logs and assigns the new scheme" do
@ -359,6 +364,7 @@ RSpec.describe Merge::MergeOrganisationsService do
merging_organisation.reload
expect(absorbing_organisation.owned_schemes.count).to eq(0)
expect(scheme.scheme_deactivation_periods.count).to eq(0)
expect(scheme.locations.first.location_deactivation_periods.count).to eq(0)
expect(owned_lettings_log.owning_organisation).to eq(merging_organisation)
expect(owned_lettings_log_no_location.owning_organisation).to eq(merging_organisation)
end
@ -676,6 +682,8 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(new_absorbing_organisation.owned_schemes.first.locations.first.old_visible_id).to be_nil
expect(scheme.scheme_deactivation_periods.count).to eq(1)
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
expect(scheme.locations.first.location_deactivation_periods.count).to eq(1)
expect(scheme.locations.first.location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
end
it "moves relevant logs and assigns the new scheme" do
@ -702,6 +710,7 @@ RSpec.describe Merge::MergeOrganisationsService do
merging_organisation.reload
expect(new_absorbing_organisation.owned_schemes.count).to eq(0)
expect(scheme.scheme_deactivation_periods.count).to eq(0)
expect(scheme.locations.first.location_deactivation_periods.count).to eq(0)
expect(owned_lettings_log.owning_organisation).to eq(merging_organisation)
expect(owned_lettings_log_no_location.owning_organisation).to eq(merging_organisation)
end
@ -842,6 +851,8 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(new_absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode)
expect(scheme.scheme_deactivation_periods.count).to eq(1)
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday)
expect(scheme.locations.first.location_deactivation_periods.count).to eq(1)
expect(scheme.locations.first.location_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday)
end
it "moves relevant logs and assigns the new scheme" do
@ -868,6 +879,7 @@ RSpec.describe Merge::MergeOrganisationsService do
merging_organisation.reload
expect(new_absorbing_organisation.owned_schemes.count).to eq(0)
expect(scheme.scheme_deactivation_periods.count).to eq(0)
expect(scheme.locations.first.location_deactivation_periods.count).to eq(0)
expect(owned_lettings_log.owning_organisation).to eq(merging_organisation)
expect(owned_lettings_log_no_location.owning_organisation).to eq(merging_organisation)
end

Loading…
Cancel
Save