Delete the notification when the WP gets destroyed

pull/9521/head
Oliver Günther 3 years ago
parent 6e90929133
commit b7874852ec
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 11
      app/services/work_packages/delete_service.rb
  2. 24
      spec/services/work_packages/delete_service_integration_spec.rb

@ -44,6 +44,7 @@ class WorkPackages::DeleteService < ::BaseServices::Delete
end
destroy_descendants(descendants, result)
delete_associated(model)
end
result
@ -58,4 +59,14 @@ class WorkPackages::DeleteService < ::BaseServices::Delete
result.add_dependent!(ServiceResult.new(success: descendant.destroy, result: descendant))
end
end
def delete_associated(model)
delete_notifications_resource(model.id)
end
def delete_notifications_resource(id)
Notification
.where(resource_type: :WorkPackage, resource_id: id)
.delete_all
end
end

@ -92,4 +92,28 @@ describe WorkPackages::DeleteService, 'integration', type: :model do
expect { work_package.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
describe 'with a notification' do
let!(:work_package) { FactoryBot.create :work_package, project: project }
let!(:notification) do
FactoryBot.create :notification,
recipient: user,
actor: user,
resource: work_package,
project: project
end
let(:instance) do
described_class.new(user: user,
model: work_package)
end
subject { instance.call }
it 'deletes the notification' do
expect(subject).to be_success
expect { work_package.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end

Loading…
Cancel
Save