diff --git a/app/workers/principals/delete_job.rb b/app/workers/principals/delete_job.rb index 4df2dafba025..60a2c5fa2d75 100644 --- a/app/workers/principals/delete_job.rb +++ b/app/workers/principals/delete_job.rb @@ -66,6 +66,7 @@ def delete_associated(principal) delete_notifications(principal) delete_private_queries(principal) delete_tokens(principal) + delete_favorites(principal) end def delete_notifications(principal) @@ -77,6 +78,10 @@ def delete_private_queries(principal) CostQuery.where(user_id: principal.id, is_public: false).delete_all end + def delete_favorites(principal) + Favorite.where(user_id: principal.id).delete_all + end + def delete_tokens(principal) ::Token::Base.where(user_id: principal.id).destroy_all end diff --git a/spec/workers/principals/delete_job_integration_spec.rb b/spec/workers/principals/delete_job_integration_spec.rb index 17596286a579..2db3e9a989c0 100644 --- a/spec/workers/principals/delete_job_integration_spec.rb +++ b/spec/workers/principals/delete_job_integration_spec.rb @@ -475,6 +475,17 @@ it_behaves_like "cost_query handling" it_behaves_like "project query handling" it_behaves_like "mention rewriting" + + describe "favorites" do + before do + project.add_favoring_user(principal) + job + end + + it "removes the assigned_to association to the principal" do + expect(project.favoring_users.reload).to be_empty + end + end end context "with a group" do