diff --git a/lib/cleanup/destroyable_records.rb b/lib/cleanup/destroyable_records.rb index 08cf370a4f4..47746e7ba6b 100644 --- a/lib/cleanup/destroyable_records.rb +++ b/lib/cleanup/destroyable_records.rb @@ -26,7 +26,7 @@ def print_data stdout.puts '********' stdout.puts 'Integration:' - if integration.nil? + if integration.blank? stdout.puts 'No associated integration' else stdout.puts integration.attributes.to_yaml @@ -46,7 +46,7 @@ def print_data stdout.puts '*******' stdout.puts 'These are the IAA orders that will be affected: \n' - if iaa_orders.nil? + if iaa_orders.blank? stdout.puts 'No IAA orders will be affected' else stdout.puts 'These are the IAA orders that will be affected: \n' @@ -79,11 +79,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 diff --git a/spec/lib/cleanup/destroyable_records_spec.rb b/spec/lib/cleanup/destroyable_records_spec.rb index d425b780ebf..269379bf495 100644 --- a/spec/lib/cleanup/destroyable_records_spec.rb +++ b/spec/lib/cleanup/destroyable_records_spec.rb @@ -106,6 +106,16 @@ 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 } + + it 'destroys the integration' do + deleted_int = Agreements::Integration.find_by(id: empty_integration.id) + expect(deleted_int).to be nil + end + end + it 'does not delete unrelated objects' do iu2.reload iaa_order.reload