Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions lib/cleanup/destroyable_records.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def print_data

stdout.puts '********'
stdout.puts 'Integration:'
if integration.blank?
if integration.nil?
stdout.puts 'No associated integration'
else
stdout.puts integration.attributes.to_yaml
Expand Down Expand Up @@ -58,15 +58,14 @@ def print_data
end

def destroy_records
stdout.puts 'Destroying integration usages'
integration_usages.each do |integration_usage|
integration_usage.destroy!
if integration.present?
stdout.puts 'Destroying integration usages'
integration_usages.destroy_all
integration.reload
stdout.puts "Destroying integration with issuer #{integration.issuer}"
integration.destroy!
service_provider.reload
end
integration.reload

stdout.puts "Destroying integration with issuer #{integration.issuer}"
integration.destroy!
service_provider.reload

stdout.puts "Destroying service provider issuer #{service_provider.issuer}"
service_provider.destroy!
Expand All @@ -79,11 +78,11 @@ def destroy_records
private

def integration_usages
integration&.integration_usages || []
integration&.integration_usages
end

def iaa_orders
integration&.iaa_orders || []
integration&.iaa_orders
end

def in_person_enrollments
Expand Down
19 changes: 15 additions & 4 deletions spec/lib/cleanup/destroyable_records_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,27 @@
expect(iaa_order.integrations.include? integration).to be false
end

describe 'integration without usages or iaa_orders' do
let!(:empty_integration) { create(:integration) }
let!(:service_provider) { empty_integration.service_provider }
context 'integration without integration usages' do
# int factory has no usages by default
let!(:integration) { create(:integration) }
let!(:service_provider) { integration.service_provider }

it 'destroys the integration' do
deleted_int = Agreements::Integration.find_by(id: empty_integration.id)
deleted_int = Agreements::Integration.find_by(id: integration.id)
expect(deleted_int).to be nil
end
end

context 'no integration' do
# sp factory has no integrations by default
let!(:service_provider) { create(:service_provider) }

it 'destroys the service provider' do
deleted_sp = ServiceProvider.find_by(id: service_provider.id)
expect(deleted_sp).to be nil
end
end

it 'does not delete unrelated objects' do
iu2.reload
iaa_order.reload
Expand Down